2012-02-13 57 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時,彩色圖像,而是當我用兩根手指滾動視圖觸摸時,我想對其進行縮放,如果用手指觸摸,必須禁用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