2012-02-07 149 views
0

我做了一個帶有頁面的UIScrollView。在每一頁上,我將有一個UIImageView與UIScrollView。我想以這種方式處理每個頁面上圖像的縮放。但縮放委託方法沒有被調用。 這裏是我的代碼:UIScrollView縮放視圖沒有被調用

verticalScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; 
      horizontalScroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; 



      verticalScroll.backgroundColor=[UIColor purpleColor]; 
      verticalScroll.pagingEnabled=YES; 
      verticalScroll.contentSize=CGSizeMake(768*[largeImagesFromGallery count], 1024); 


      horizontalScroll.backgroundColor=[UIColor blackColor]; 
      horizontalScroll.pagingEnabled=YES; 
      horizontalScroll.contentSize=CGSizeMake(1024*[largeImagesFromGallery count], 768); 

      float cofVert=1.34f; 
      for(int i=0; i<[largeImagesFromGallery count]; i++) 
      { 
       UIImage *temp=[largeImagesFromGallery objectAtIndex:i]; 

       UIScrollView *svVert=[[UIScrollView alloc] initWithFrame:CGRectMake(i*768, 0, temp.size.width/cofVert, temp.size.height/cofVert)]; 

       svVert.contentSize=CGSizeMake(temp.size.width/cofVert, temp.size.height/cofVert); 
       svVert.zoomScale=3.0f; 
       svVert.delegate=self; 


       UIImageView *imageVert=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, temp.size.width/cofVert, temp.size.height/cofVert)]; 
       imageVert.image=temp; 

       imageVert.tag=2000; 


       UIScrollView *svHor=[[UIScrollView alloc] initWithFrame:CGRectMake(i*1024, 0, temp.size.width, temp.size.height)]; 
       svHor.delegate=self; 
       svHor.contentSize=CGSizeMake(temp.size.width, temp.size.height); 

       UIImageView *imageHor=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, temp.size.width, temp.size.height)]; 
       imageHor.image=temp; 
       imageHor.tag=2000; 

       [svVert addSubview:imageVert]; 
       [svHor addSubview:imageHor]; 
       [verticalScroll addSubview:svVert]; 
       [horizontalScroll addSubview:svHor]; 


        //fr=CGRectMake(0, 0, 768, 1024); 
        //[verticalScroll addSubview:imageVert]; 
        // [horizontalScroll addSubview:imageHor]; 


      } 
      //verticalScroll.delegate=self; 
      // horizontalScroll.delegate=self; 
      ambiancesON=YES; 
      if(self.interfaceOrientation==UIInterfaceOrientationPortrait || self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) 
      { 
       [self.view addSubview:verticalScroll]; 
      } 
      else if(self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation==UIInterfaceOrientationLandscapeRight) 
      { 
       [self.view addSubview:horizontalScroll]; 

      } 

所以現在我有變焦方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 

    NSLog(@"Log log log"); 
    NSLog(@"VIew? %@", [[scrollView subviews]objectAtIndex:0]); 

    return [[scrollView subviews]objectAtIndex:0]; 
} 

變焦不會被調用((

回答

1

我認爲這是在你的設計有一個缺點我會。建議爲每個內部滾動視圖創建一個視圖控制器類(您想對縮放做出響應的視圖控制器類)。這樣,如果所有東西都連線正確(UIScrollView委託被分配給內部視圖控制器),它應該如您所期望的那樣工作