我有这个代码:
[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 之后必须禁用。 使用我的代码不会发生;它识别双击但不主动缩放,为什么?
最佳答案
我认为问题在于您没有实现所有必需的缩放委托(delegate)方法。
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.
希望对您有所帮助。
关于IOS:仅使用多点触控缩放 uiscrollview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9263978/