限制UISwipeGestureRecognizer区域

时间:2017-02-05 14:21:34

标签: ios swift xcode

我正在使用多个UISwipeGestureRecognizer作为菜单的选择器。由于我有不止一个,我需要有一个有限的刷卡检测区域。这是我正在使用的代码:

 var rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipe1"))

 rightSwipe.direction = .right

 view.addGestureRecognizer(rightSwipe)

我已经尝试将其添加到UIImageView但它不会检测到触摸。

2 个答案:

答案 0 :(得分:0)

我只需要添加<?php header('Access-Control-Allow-Origin: *'); header("Access-Control-Allow-Headers: Origin, X-Requested-With,Content-Type, Accept"); header('Access-Control-Allow-Methods: GET, POST, PUT'); echo "Success"; ?> 。这是我的代码:

.isUserInteractionEnabled = true

答案 1 :(得分:0)

默认情况下,isUserInteractionEnabledUIImage

UILabel为false。将其设置为true。

据我所知,你无法限制手势区域。但是你可以检查手势的位置并决定如何处理它。

例如:

func addGesture() {
    let rightGesture = UISwipeGestureRecognizer(target: self, action: #selector(someAction(sender:)))
    rightGesture.direction = .right

    let leftGesture = UISwipeGestureRecognizer(target: self, action: #selector(someAction(sender:)))
    leftGesture.direction = .right

    view.addGestureRecognizer(rightGesture)
    view.addGestureRecognizer(leftGesture)
}

func someAction(sender: UISwipeGestureRecognizer) {
    let location = sender.location(in: view)
    if location.x > view.frame.width / 2 && sender.direction == .right {
        // do something
    } else if location.x < view.frame.width / 2 && sender.direction == .left {
        // do something else
    }
}