简体   繁体   English

GestureRecogniser并在UIScrollView中禁用UIView的拖动手势

[英]GestureRecogniser and disabling drag gesture of a UIView in a UIScrollView

Recently I had a problem. 最近我遇到了问题。 How to disable scrolling in a particular area of a UIScrollView, particularly the area occupied by a UIView or subview. 如何禁用UIScrollView的特定区域中的滚动,尤其是UIView或子视图占用的区域。 I've readen a lot about subclassing and other long approaches to solve this. 我已经了解了很多关于子类化和其他长方法来解决这个问题。 But recently I solved this problem in a simplier manner without subclassing: 但最近我在没有子类化的情况下以简单的方式解决了这个问题:

UIPanGestureRecognizer *panrecognizer = [[UIPanGestureRecognizer alloc] init];

and then 接着

[panrecognizer setCancelsTouchesinView:NO];
[mySubViewInScroll addGestureRecognizer:panrecognizer];

I created the UIPanGestureRecognizer without an Action passed to it and then added the recognizer to the view in the scroller. 我创建了UIPanGestureRecognizer而没有传递给它的Action,然后将识别器添加到滚动条中的视图。 In such way the gestures on the view will be captured but expressly not handled by the view or by the superviews because we passed to the object no Action. 以这种方式,视图上的手势将被捕获,但明确地不由视图或超级视图处理,因为我们传递给对象没有Action。 The question is this. 问题是这个。 Is this a correct approach to handle this type of prolem or it's better to do otherwise. 这是处理此类问题的正确方法,还是最好不要这样做。 I mean Apple will accept this kind of application with this approach ? 我的意思是Apple会用这种方法接受这种应用吗?

try rewrite ScrollView's 尝试重写ScrollView的

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

to return chi 返回chi

In effect I think that this, even if not the best is the most practical solution..since messing around with the classes and subclassing to achieve only a partial scroll lock of the screen seems to be very odd. 实际上我认为,即使不是最好的也是最实用的解决方案。因为乱搞类和子类只能实现屏幕的部分滚动锁定似乎很奇怪。 So let-s see if Apple will accept this kind of solution... 那么让我们看看Apple是否会接受这种解决方案......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在uiscrollview iOS中向uiview添加拖动手势 - How to add drag gesture to uiview in uiscrollview ios UIVcrollView里面的UIView,UIView手势单行 - UIScrollView inside UIView, UIView gesture one-liner 在UIScrollView中使用滑动手势而不禁用水平和垂直滚动 - Using swipe gesture within UIScrollView without disabling horizontal and vertical scrolling 将捏手势从自定义UIView传递到父UIScrollView - Pass pinch gesture from custom UIView to parent UIScrollView 点击手势识别器不适用于UIVcrollView内的UIWebiew,它位于UIView内部 - Tap gesture recognizer Not working for UIWebiew inside UIScrollView,which is inside UIView 将UIView从UIPopOverController中的UIScrollView拖放到主UIViewController? - Drag and Drop UIView from a UIScrollView within a UIPopOverController to main UIViewController? 拖动 UIView 而不禁用其子控件 iPhone/iPad - Drag UIView without disabling its child controls iPhone/iPad 在UIScrollView中拖动时,UIView和UIControl之间有所不同 - Different between UIView and UIControl when drag inside UIScrollView uiview和uiscrollview - uiview and uiscrollview 分页UIScrollView中手势识别器sender.view上的怪异行为UIView动画 - Weird behavior UIView animation on gesture recognizer's sender.view in paging UIScrollView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM