2010-03-04 61 views

回答

0

蘋果有一個非常好的示例代碼,全部關於UIScrollView和縮放和平鋪。瞧瞧吧

http://developer.apple.com/iphone/library/samplecode/ScrollViewSuite/index.html

此代碼是在WWDC2009的Scoll意見會議討論。遺憾的是,該會議的視頻並不是免費的,但您可以將其作爲iPhone WWDC2009視頻包的一部分購買。

+0

謝謝 - 會看看它。之前錯過了,因爲這是從下載沒有工作的文檔中唯一的例子... – Jean

1

我終於通過在scrollview中放置scrollview來實現它。 通過這種方式,內部視圖可在外部手柄縮放時處理頁面滑動。

+0

很棒...爲我工作也...謝謝... :) – 2012-02-06 12:49:46

+0

你能分享代碼嗎? – Walucas

0

只要在另一個滾動視圖。

就像是:

-(void)zoomToSelectedImage:(NSIndexPath *)indexPath 
    { 

     int currentPage = indexPath.row; 

    //The External Scrollview. It move back and forward 
     UIScrollView *contentViewZoom = [[UIScrollView alloc] initWithFrame:self.frame]; 
     [contentViewZoom setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.8]]; 
     [contentViewZoom setContentSize:CGSizeMake(contentViewZoom.frame.size.width * [arrayOfImages count], contentViewZoom.frame.size.height)]; 
     [contentViewZoom setPagingEnabled:YES]; 
     [contentViewZoom setDelegate:self]; 


     for (int i = 0; i < [arrayOfImages count]; i++) { 
     CGRect frame; 
     frame.origin.x = contentViewZoom.frame.size.width * i; 
     frame.origin.y = 0; 
     frame.size = contentViewZoom.frame.size; 

     //The Internal Scrollview. It allow you zoom the picture 

     UIScrollView *imageScrollView = [[UIScrollView alloc]initWithFrame:frame]; 
     [imageScrollView setTag:1]; 
     [imageScrollView setMinimumZoomScale:1.0]; 
     [imageScrollView setMaximumZoomScale:3.0]; 
     [imageScrollView setAlpha:1]; 
     [imageScrollView setDelegate:self]; 
     [imageScrollView setBouncesZoom:YES]; 
     [imageScrollView setClipsToBounds:YES]; 
     [imageScrollView setShowsHorizontalScrollIndicator:NO]; 
     [imageScrollView setShowsVerticalScrollIndicator:NO]; 
     [imageScrollView setContentSize:CGSizeMake(768, 1024)]; 


     UIImage *image = [arrayOfImages objectAtIndex:i]; 
     UIImageView* imgView = [[UIImageView alloc] init]; 
     [imgView setImage:image]; 
     [imgView setFrame:CGRectMake(0, 0, 768, 1024)]; 
     imgView.bounds = self.bounds; 
     [imgView setClipsToBounds:YES]; 
     [imgView setContentMode:UIViewContentModeScaleAspectFit]; 
     [imgView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 

     [imageScrollView addSubview:imgView]; 
     [contentViewZoom addSubview:imageScrollView]; 

     } 


     [self addSubview:contentViewZoom]; 
     [contentViewZoom setAlpha:0.2]; 


     //Positioning according to current position 
     CGRect frame; 
     frame.origin.x = contentViewZoom.frame.size.width * currentPage; 
     frame.origin.y = 0; 
     frame.size = contentViewZoom.frame.size; 
     [contentViewZoom scrollRectToVisible:frame animated:NO]; 

    } 

OBS:在我的情況下,屏幕尺寸是固定的(768×1024),因爲你需要,你應該改變。