2009-09-28 100 views
0

使用OS 3.1我在UIScrollView中放置了一個輕敲檢測圖像視圖(取自Apple的Scroll View套件示例),並且想要在圖像視圖出現時放大兩次圖像視圖。第一個縮放是爲了使整個圖像可見,第二個縮放是放大到指定的區域。我現在所擁有的是:背靠背UIScrollView縮放

- (void)viewDidLoad { 
    // After adding scroll view and image view 
    imageScrollView.minimumZoomScale = 0.5; 
    imageScrollView.maximumZoomScale = 2.75; 
    imageScrollView.zoomScale = 1.0; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1];  
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDelegate: self]; 
    [imageScrollView zoomToRect:[imageView frame] animated:YES]; 
    [UIView commitAnimations]; 

和下面以檢測第一變焦結束,並觸發第二:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale { 
    selectedRect.origin.x = 60.0; 
    selectedRect.origin.y = 90.0; 
    selectedRect.size.width = 90.0; 
    selectedRect.size.height = 90.0; 

    imageScrollView.minimumZoomScale = 1.0; 
    imageScrollView.maximumZoomScale = 2.75; 
    imageScrollView.zoomScale = 2.5; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1];  
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDelegate: self]; 
    [imageScrollView zoomToRect:selectedRect animated:YES]; 
    [UIView commitAnimations]; 

什麼情況是,這會導致一個無限循環和滾動在兩個放大點之間反覆查看「擺動」。我應該做什麼不同?謝謝。

回答

1

當然你只需要檢查當前的zoomScale作爲scrollViewDidEndZooming中的第一個動作。如果您已經放大,請不要執行新的縮放。