2014-12-04 55 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

相關問題