0

在使用 UIScrollView 的缩放功能之前,一切都很好。代码如下:

 UIScrollView* scrollView = [[UIScrollView alloc]init];
   for(int i=0; i < foodIntroCount; ++i) {
        UIImage* image = [UIImage imageNamed:@"7_1.jpg"];
        UIImageView * imgView = [[UIImageView alloc]initWithImage:image];
        imgView.frame = CGRectMake(0, height*i, width, height);
        [scrollView addSubView:imgView];
   }

   scrollView.contentSize =  CGSizeMake(width, height*(foodIntroCount+1)) ;
   scrollView.pagingEnabled = YES; 
   scrollView.showsVerticalScrollIndicator = NO;
   scrollView.showsHorizontalScrollIndicator = NO;
   scrollView.bounces = NO;
   scrollView.delegate = self;


   _foodWineViewController = [[OHFoodWineViewController alloc]initWithCategoryData:_foodData];
   UIView* wineView = _foodWineViewController.view;
   wineView.frame = CGRectMake(0, height*(foodIntroCount), width, height);
   [scrollView addSubview:wineView];

添加缩放功能后,代码如下所示:

UIScrollView* scrollView = [[UIScrollView alloc]init];
UIView* zoomView = [[UIView alloc]init];
   for(int i=0; i < foodIntroCount; ++i) {
        UIImage* image = [UIImage imageNamed:@"7_1.jpg"];
        UIImageView * imgView = [[UIImageView alloc]initWithImage:image];
        imgView.frame = CGRectMake(0, height*i, width, height);
        [zoomView addSubView:imgView];
   }

   scrollView.contentSize =  CGSizeMake(width, height*(foodIntroCount+1)) ;
   scrollView.pagingEnabled = YES; 
   scrollView.showsVerticalScrollIndicator = NO;
   scrollView.showsHorizontalScrollIndicator = NO;
   scrollView.bounces = NO;
   scrollView.delegate = self;
   scrollView.maximumZoomScale = 2.0;


   _foodWineViewController = [[OHFoodWineViewController alloc]initWithCategoryData:_foodData];
   UIView* wineView = _foodWineViewController.view;
   wineView.frame = CGRectMake(0, height*(foodIntroCount), width, height);
   [zoomView addSubView:wineView];
   [scrollView addSubview:zoomView];

问题是:wineView 显示在第一页,而不是 foodIntroCount+1 页面。

4

1 回答 1

0

如果您想一个接一个地垂直添加子视图,您的代码应该考虑之前的y 位置高度。所以你的代码应该如下所示

imgView.frame = CGRectMake(0, height*i+y, width, height);

代码没有经过测试,试试这个..

于 2013-04-05T05:28:23.577 回答