2010-08-13 93 views

回答

1

你可能想要做這樣的事情:

- (void) resizeScrollContentView 
{ 
    CGSize viewSize = _imageView.frame.size; 
    CGSize scrollSize = _scroll.frame.size; 
    CGPoint p; 

    p.x = 0; 
    p.y = 0; 

    if(viewSize.width < 320) 
    { 
     p.x = 160 - (viewSize.width/2.0); 
    } 

    if(viewSize.height < 460) 
    { 
     p.y = 200 - (viewSize.height/2.0); 
    } 

    _imageView.frame = CGRectMake(p.x, p.y, _imageView.frame.size.width, _imageView.frame.size.height); 

    CGSize endScrollSize; 
    endScrollSize = _imageView.frame.size; 

    _scroll.contentSize = endScrollSize; 
} 
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale 
{ 
    [self resizeScrollContentView]; 
} 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 
{ 
    return _imageView; 
} 
+0

謝謝,但究竟是什麼呢?我不得不在IB中做任何事情? – jarryd 2010-08-13 22:25:26

+1

它將imageView綁定到scrollingView,並在縮放時調整它的大小。如果縮放比手機大小大,它可以讓你滾動。 不,你不必在IB上做任何事......只需創建名爲_scroll的ScrollView,並在這裏調用UIImageView _imageView – TheSquad 2010-08-13 22:34:43

+0

我試過這個,也設置了我的imageview.image,但視圖只顯示爲空白。在IB中做這件事更容易嗎? – jarryd 2010-08-13 23:34:15