2014-12-04 53 views
1

我是iPhone开发新手。我在包含在另一个UIScrollView(scrollViewgalery)中的UIScrollView(zoomscrollView)中包含的UIImageView中有一个图像。ScrollView在敲击时向上移动

我的问题是,虽然在触摸第一个滚动视图,即zoomScrollview,它会向上移动。

回答

2
I Hope you need a view similar to photos gallery view. Here u will need a main scrollviewGallery and inside it your scrollviewZoom whose height should be same as scrollViewGallery for horizontal scroll and scrollViewZooms width should be same as scrollViewGallery for vertical scroll. Also Make sure u have enabled pagination for scrollViewGallery. 


Your sample code goes here 
       [_scrollView setDelegate:self]; 
    int index=0; 
     for (NSString* stringImageName in self.arrayGalleryImages) 
     { 
    UIScrollView *imgScroll=[[UIScrollView alloc]initWithFrame:CGRectMake(index*CGRectGetWidth(_scrollView.frame),0,CGRectGetWidth(_scrollView.frame),CGRectGetHeight(_scrollView.frame))]; 
       [imgScroll setDelegate:self]; 
       [imgScroll setTag:index]; 
       [imgScroll setScrollEnabled:NO]; 
       [imgScroll setMinimumZoomScale:1.0]; 
       [imgScroll setMaximumZoomScale:3.0]; 
       [imgScroll setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; 

       UIButton *btnGallery=[[UIButton alloc] initWithFrame: imgScroll.bounds]; 
       [btnGallery addTarget:self action:@selector(gotoFullScreenGallery) forControlEvents:UIControlEventTouchUpInside]; 
       [btnGallery setAdjustsImageWhenHighlighted:NO]; 
       [btnGallery setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; 
       [btnGallery setTag:index]; 
       [[btnGallery imageView] setContentMode: UIViewContentModeScaleAspectFit]; 
    [btnGallery setImage:[UIImage imageNamed:stringImageName] forState:UIControlStateNormal]; 
    [imgScroll addSubview:btnGallery]; 
       [_scrollView addSubview:imgScroll]; 
      index++; 
     } 
     [_scrollView setContentSize:CGSizeMake(index*CGRectGetWidth(_scrollView.frame), CGRectGetHeight(_scrollView.frame))]; 

Assuming arrayGalleryImages consists of gallery image names. 
I used button to add more action on tap. 


Try code and manage scrollview delegate methods 

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
    { 
     if([previouslyZoomedScroll zoomScale]!=1.0) 
     { 
      [previouslyZoomedScroll setZoomScale:1.0]; 
     } 
    } 
+0

我已经使用这个代码: - (无效)scrollViewWillBeginDecelerating:(UIScrollView中*)滚动视图 { [滚动视图setContentOffset:scrollView.contentOffset动画:YES]; },这帮助我停止UIScrollView的垂直移动。但现在我面临着水平滚动的问题,即在分页中我有问题。页面不太流畅。 – adi012 2014-12-05 04:09:20

相关问题