iOS: Can I override pinch in/out behavior of UIScrollView?(iOS:我可以覆盖 UIScrollView 的收缩/收缩行为吗?)
问题描述
我正在 UIView 上绘制图形,该图形包含在 UIScrollView 中,以便用户可以水平滚动以查看整个图形.
I'm drawing a graph on a UIView, which is contained by a UIScrollView so that the user can scroll horizontally to look around the entire graph.
现在我想在用户用两根手指捏合时缩放图表,但我不想以相同的速率在 X 和 Y 方向上缩放视图,而是想通过更改 X 比例仅在 X 方向上缩放, 不改变 Y 比例.
Now I want to zoom the graph when a user pinches in with two fingers, but instead of zooming in a view with the same rate for X and Y direction, I want to zoom only in the X direction by changing the X scale, without changing the Y scale.
我想我必须抓住捏合/张开手势并重新绘制图形,覆盖默认的缩放行为.
I think I have to catch the pinch in/out gesture and redraw the graph, overriding the default zooming behavior.
但是有没有办法做到这一点?
But is there a way to do this?
我一直很难捕捉到 UIScrollView 上的捏合手势,因为它会在开始滚动时取消触摸.即使在 UIScrollView 取消触摸后,我也希望缩放工作.:(
I've been having a very difficult time to catch the pinch gesture on the UIScrollView, as it cancels the touches when it starts to scroll. I want the zooming to work even after the UIScrollView cancels the touches. :(
谢谢,库拉
推荐答案
虽然不能删除现有的捏合手势识别器,但可以禁用它,然后添加自己的:
Although you cannot delete the existing pinch gesture recognizer, you can disable it and then add your own:
// Disable existing recognizer
for (UIGestureRecognizer* recognizer in [_scrollView gestureRecognizers]) {
if ([recognizer isKindOfClass:[UIPinchGestureRecognizer class]]) {
[recognizer setEnabled:NO];
}
}
// Add our own
UIPinchGestureRecognizer* pinchRecognizer =
[[UIPinchGestureRecognizer alloc] initWithTarget:self
action:@selector(pinch:)];
[_scrollView addGestureRecognizer:pinchRecognizer];
[pinchRecognizer release];
然后在
- (void) pinch:(UIPinchGestureRecognizer*)recognizer { .. }
使用
[recognizer locationOfTouch:0 inView:..]
[recognizer locationOfTouch:1 inView:..]
判断用户是水平捏还是竖捏.
to figure out if the user is pinching horizontally or vertically.
这篇关于iOS:我可以覆盖 UIScrollView 的收缩/收缩行为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS:我可以覆盖 UIScrollView 的收缩/收缩行为吗?
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
