2012-12-18 47 views
0

我實現imageview在我的應用程序scrollview應用縮放某些部分不能變焦。 我想在視圖的右上方設置scrollviewimageview。但它並沒有放大。當我把它放在view的中心時,它變焦了。的ImageView在滾動視圖中的視圖

的代碼如下

@interface przoomViewController : UIViewController<UIScrollViewDelegate> 

{  
    IBOutlet UIScrollView *scrollView; 
    IBOutlet UIImageView *image;  
} 

    -(void)viewDidLoad 
{ 
    [image setUserInteractionEnabled:YES]; 
    [scrollView addSubview:image]; 
    scrollView.scrollEnabled = YES; 
    scrollView.minimumZoomScale=1.0; 
    scrollView.maximumZoomScale=4.0; 
    [scrollView setContentSize:CGSizeMake(320, 180)]; 
    scrollView.delegate=self; 

} 
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 
{ 
    return image; 
} 

給請幫助我。

回答

0

你應該爲scrollviewzoomScale屬性設置值開始縮放爲如下。

scrollView.zoomScale=1.0; // this will enable zooming. 
0

我已經在我的應用程序中實現了圖像縮放。嘗試scrollviewDelegate方法

- (void)scrollViewDidZoom:(UIScrollView *)scrollView 
{ 
    // The scroll view has zoomed, so we need to re-center the contents 
    [self centerScrollViewContents]; 
} 

- (void)centerScrollViewContents 
{ 
    CGSize boundsSize = zoomingScrollView.bounds.size; 
    CGRect contentsFrame = ZImageView.frame; 

    if (contentsFrame.size.width < boundsSize.width) 
    { 
    contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width)/2.0f; 
    } 
    else 
    { 
    contentsFrame.origin.x = 0.0f; 
    } 

    if (contentsFrame.size.height < boundsSize.height) 
    { 
    contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height)/2.0f; 
    } 
    else 
    { 
    contentsFrame.origin.y = 0.0f; 
    } 

    ZImageView.frame = contentsFrame; 
} 

無需在imageView上設置userInterAction。如果這沒有幫助,我會分享我的實施。

+0

嗨scrollViewDidZoom其不調用我的代碼 – Rajneesh071

+0

setZoomEnabled屬性是UIScrollView – fibnochi

+0

沒有任何屬性setZoomEnable scrollView – Rajneesh071

相關問題