2012-04-11 55 views
2

我試圖在iPhone上覆制照片應用程序。意思是一個帶有多個圖像的滾動視圖,並且每個圖像都可以捏合以放大/縮小。UIScrollview帶有多個圖像並捏合以進行縮放

蘋果ScrollViewSuite示例代碼僅一個滾動視圖的內部與1個圖像的交易。我發現使用多個圖像時,滾動圖像變得不可預知。此外,視圖在捏縮放後會變得不明顯。

我搜索計算器和發現this

不過,我想一些更多的細節,如果可能的話。我應該在scrollview委託函數中寫什麼?

任何幫助(例如代碼,如果可能的話)將是巨大的。

謝謝!

+1

如何對蘋果[PhotoScroller](http://www.google.co.in/url?sa=t&rct=j&q=photoscroller%20apple%20sample&source=web&cd=1&ved=0CCYQFjAA&url=http%3A%2F %2Fdeveloper.apple.com%2Flibrary%2Fios%2Fsamplecode%2FPhotoScroller%2FIntroduction%2FIntro.html&EI = B0OFT7CzEY_SrQeJ2rXSBg&USG = AFQjCNHK6ZW1WphEOlE6XEu7OhfRJ7Zi1g)應用程序? – 2012-04-11 08:39:16

回答

5

這是我找到的工作。通過分頁和縮放支持多個圖像。請享用!

#define VIEW_FOR_ZOOM_TAG (1) 

@implementation SVViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; 
    mainScrollView.pagingEnabled = YES; 
    mainScrollView.showsHorizontalScrollIndicator = NO; 
    mainScrollView.showsVerticalScrollIndicator = NO; 

    CGRect innerScrollFrame = mainScrollView.bounds; 

    for (NSInteger i = 0; i < 3; i++) { 
     UIImageView *imageForZooming = [[UIImageView alloc] initWithImage:[UIImage imageNamed: 
     [NSString stringWithFormat:@"page%d", i + 1]]]; 
     imageForZooming.tag = VIEW_FOR_ZOOM_TAG; 

     UIScrollView *pageScrollView = [[UIScrollView alloc] initWithFrame:innerScrollFrame]; 
     pageScrollView.minimumZoomScale = 1.0f; 
     pageScrollView.maximumZoomScale = 2.0f; 
     pageScrollView.zoomScale = 1.0f; 
     pageScrollView.contentSize = imageForZooming.bounds.size; 
     pageScrollView.delegate = self; 
     pageScrollView.showsHorizontalScrollIndicator = NO; 
     pageScrollView.showsVerticalScrollIndicator = NO; 
     [pageScrollView addSubview:imageForZooming]; 

     [mainScrollView addSubview:pageScrollView]; 

     if (i < 2) { 
      innerScrollFrame.origin.x += innerScrollFrame.size.width; 
     } 
    } 

    mainScrollView.contentSize = CGSizeMake(innerScrollFrame.origin.x + 
    innerScrollFrame.size.width, mainScrollView.bounds.size.height); 

    [self.view addSubview:mainScrollView]; 
} 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { 
    return [scrollView viewWithTag:VIEW_FOR_ZOOM_TAG]; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (BOOL)shouldAutorotate { 
    return NO; 
} 

@end