2012-02-13 20 views
1

とUIScrollViewのためにズーム:IOS:私はこのコードを持っている唯一のマルチタッチ

[scrollView setMinimumZoomScale:1.00]; 
[scrollView setMaximumZoomScale:2.00]; 
scrollView.delegate=self; 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    NSSet *allTouches = [event allTouches]; 
    if ([allTouches count] == 2) { 

     NSLog(@"multitouch"); 
     zoomMultiTouch = TRUE; 


    } 

    else if ([allTouches count] == 1){ 

     NSLog(@"single touch"); 
     zoomMultiTouch = FALSE; 
    } 

    else return; 

} 


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 


    if (zoomMultiTouch){ 
     scrollView.userInteractionEnabled = YES; 
     scrollView.scrollEnabled = YES; 
     NSLog(@"zoomMultitouch moved"); 
    } 

    else { 
     scrollView.userInteractionEnabled = NO; 
     scrollView.scrollEnabled = NO; 
     NSLog(@"NOzoom moved"); 
    } 

    //some code for coloring an image 

} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    scrollView.userInteractionEnabled = NO; 
    scrollView.scrollEnabled = NO; 
    zoomMultiTouch = FALSE; 
} 

あなたが見ることができるように、私は内部の画像でscrollViewを拡大したいと。私が2つの指スクロールビューでタッチするときに、私はそれをズームしたい、そしてその後、私が指でタッチすると、zommを無効にする必要があります。 私のコードでは起こりません。ダブルタッチを認識しますが、アクティブズームはしません。なぜですか?

答えて

0

私は、ズームに必要なすべてのデリゲートメソッドを実装していないという問題があると思います。

The UIScrollView class can have a delegate that must adopt the UIScrollViewDelegate protocol. For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:; in addition, the maximum (maximumZoomScale) and minimum (minimumZoomScale) zoom scale must be different. 

それがお役に立てば幸いです。

UIScrollView Class Reference

関連する問題