iOS:仅通过多点触控缩放 uiscrollview
我有这样的代码:
[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;
}
如你所见,我想缩放滚动视图,其中包含图像;当我用手指触摸滚动视图时,我对图像进行着色,而当我用两根手指触摸滚动视图时,我想对其进行缩放,并且如果我用手指触摸,则必须禁用缩放。 使用我的代码不会发生这种情况;它可以识别双击,但不能主动缩放,为什么?
I have this code:
[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;
}
as you can see, I want to zoom scrollView with an image inside; when I touch scrollView with a finger I color image, instead when I touch with two fingers scrollview, I want to do a zoom on it, and after if I touch with a finger zomm must be disabled.
with my code it don't happen; it recognize double touch but don't active zoom, why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于您没有实现缩放所需的所有委托方法。
希望有帮助。
UIScrollView 类参考
I think the problem is that you are not implementing all required delegate methods for zooming.
Hope it helps.
UIScrollView Class Reference