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 的收缩/收缩行为吗?
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01