我有这段代码:
[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;当我用手指触摸scrollView时我用彩色图像,而当我用两个手指触摸scrollview时,我想对它进行缩放,然后如果我用手指触摸,则必须禁用zomm。 我的代码不会发生;它识别双重触摸,但不主动缩放,为什么?
答案 0 :(得分: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.
希望它有所帮助。