简体   繁体   English

触摸按钮(子视图)时,不要在超级视图上处理平移手势

[英]Don't handle pan gesture on superview when touchdown button (subview)

I have a view(superview) which I can move by pan gesture, This view has subview(UIButton) with TouchDown Event. 我有一个可以通过平移手势移动的视图(超级视图),该视图具有带有TouchDown事件的子视图(UIButton)。 But when I press button(touchdown event handled) and continue move finger my superview start handling pan gesture method. 但是当我按下按钮(处理了触地事件)并继续移动手指时,我的超级视图开始处理平移手势方法。 How disable handling pan gesture method of superview when I touchdown its subview? 当我降落其子视图时,如何禁用处理超级视图的平移手势方法?

for disabling touch events on UIView's subviews you can add this extension to UIViewController : 要在UIView的子视图上禁用触摸事件,可以将此扩展添加到UIViewController

extension UIViewController:UIGestureRecognizerDelegate {
    func hideKeyboardWhenTappedAround() {
        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
        view.addGestureRecognizer(tap)
        tap.delegate = self
    }

    func dismissKeyboard() {
        view.endEditing(true)
    }
    public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
       if (touch.view!.isDescendantOfView(self.view) && touch.view != self.view){
            return false
        }
        return true
    }
}

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

相关问题 防止超级视图识别平移手势(在iOS 7中) - Prevent the superview recognizing the pan gesture (in iOS 7) 如何阻止从超级视图到子视图的手势? - How to block a gesture from superview to subview? 将按钮作为子视图,单击开始超级视图 - Button as subview, click start superview superview的手势是否应取消iOS 7中子视图的手势? - Should superview's gesture cancel subview's gesture in iOS 7? 子视图(UILabel)放置在超级视图(UITextView)中时不遵守约束 - Subview (UILabel) doesn't respect the constraints when placed in superview (UITextView) 当superview具有手势时,collectionView没有调用didSelectItemAtIndexPath - collectionView didn't call didSelectItemAtIndexPath when superview has gesture 平移手势不适用于 controller 中的按钮 - pan gesture is not working for button in controller MKannotationView,UIButton作为子视图,按钮不响应 - MKannotationView with UIButton as subview, button don't respond 将按钮视图添加到标签视图作为子视图时,手势识别器无法正常工作 - Gesture recogniser not working when added button view to the Label view as subview 使用Superview的按钮将特定的子视图加载到容器中 - Load a specific subview into a container with superview's button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM