gestureRecognizer无法处理添加的子视图

时间:2016-02-29 18:15:59

标签: ios swift uigesturerecognizer uibezierpath

我在视图中添加了一个包含多个手势识别器的子视图,但是当引入此视图时,当用户点击这个新添加的视图时,手势不会触发。然而,这是我引入的UIBezierPath。我读过这可能是它不起作用的方式。我的问题是,是否可以使添加的UIBezierPath透明,使设备认为正在点击绘制框下方的视图。我希望我说的是有道理的。

这是我的UIBezierPath

的代码
class drawRecognizerIndicator{
let gestureContainer: UIView!
var view_gesture: UIView!

init(container: UIView){
    gestureContainer = container
}

func drawRect(image: UIImage){
    let screenSize = gestureContainer.bounds
    let screenWidth = screenSize.width
    let screenHeight = screenSize.height

    let gestureX = (screenWidth * 0.75) * 0.5
    let gestureY = (screenWidth * 0.75) * 0.5
    let gestureWidth = (screenWidth * 0.75)
    let gestureHeight = (screenWidth * 0.75)

    if(view_gesture != nil){
        if(view_gesture.isDescendantOfView(gestureContainer)){
            view_gesture.removeFromSuperview()
        }
    }

    view_gesture = UIView(frame: CGRect(
        x: (screenWidth * 0.5) - gestureX,
        y: (screenHeight * 0.5) - gestureY ,
        width: gestureWidth,
        height: gestureHeight))
    view_gesture.backgroundColor = UIColor.blackColor()
    view_gesture.alpha = 0

    let maskPath = UIBezierPath(roundedRect: view_gesture.bounds, byRoundingCorners: .AllCorners, cornerRadii: CGSize(width: 10, height: 10))
    let maskLayer = CAShapeLayer(layer: maskPath)
    maskLayer.frame = view_gesture.bounds
    maskLayer.path = maskPath.CGPath
    view_gesture.layer.mask = maskLayer

    let view_gestureSize = view_gesture.bounds
    let gestureIconWidth = view_gestureSize.width
    let gestureIconHeight = view_gestureSize.height

    let iconX = (gestureIconWidth * 0.8) * 0.5
    let iconY = (gestureIconHeight * 0.8) * 0.5
    let iconWidth = gestureIconWidth * 0.8
    let iconHeight = gestureIconHeight * 0.8

    let image_gesture = UIImageView(frame: CGRect(
        x: (gestureIconWidth * 0.5) - iconX,
        y: (gestureIconHeight * 0.5) - iconY,
        width: iconWidth,
        height: iconHeight))
    image_gesture.contentMode = UIViewContentMode.ScaleAspectFit
    image_gesture.image = image
    image_gesture.userInteractionEnabled = true
    view_gesture.addSubview(image_gesture)
    view_gesture.userInteractionEnabled = true
    gestureContainer.addSubview(view_gesture)
    animateGestureNotification(view_gesture)
}

func animateGestureNotification(view_gesture: UIView){
    UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
        view_gesture.alpha = 0.4
        }, completion: nil)

    UIView.animateWithDuration(0.5, delay: 2, options: UIViewAnimationOptions.CurveEaseOut, animations: {
        view_gesture.alpha = 0
        }, completion: nil)
}
}

1 个答案:

答案 0 :(得分:0)

查看文档

TabItems

有助于确定在同一个视图控制器上有多个手势识别器时会发生什么。

我首先要在其中放置一些打印语句,以确切地查看正在调用哪些GR,然后确定哪些GR应该返回true。

相关问题