轻扫手势识别器迅速

时间:2016-01-09 16:25:10

标签: ios swift2 uiswipegesturerecognizer ios9.1

我一直在互联网上看几个小时如何使用Swipe Gesture Recognizer。我不想对它进行编码,因为我几乎尝试过每一个例子而且没有用。但是,我知道对象库中有一个Swipe Gesture Recognizer,但它似乎不起作用。有人可以给我一个指向我可以使用对象库中的Swipe Gesture Recognizer的地方的链接,或者告诉我该怎么做?

谢谢,

(如果由于某种原因我要宽泛,或者你不喜欢我的问题,请不要-1这个,只是评论,我会做出改变,请。)

崩溃日志: 2016-01-09 10:59:33.392 Capitals [250:14059] - [Capitals.Alabama1 handleSwipes]:无法识别的选择器发送到实例0x14f695150 2016-01-09 10:59:33.397首都[250:14059] *由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [Capitals.Alabama1 handleSwipes]:无法识别选择器发送到实例0x14f695150' * 第一次抛出调用堆栈: (0x184bdcf48 0x19984ff80 0x184be3c5c 0x184be0c00 0x184ae4cac 0x18a6eb330 0x18a314b5c 0x18a1a285c 0x18a6ec70c 0x18a1618b8 0x18a15e63c 0x18a1a06cc 0x18a19fcc8 0x18a1704a4 0x18a16e76c 0x184b94544 0x184b93fd8 0x184b91cd8 0x184ac0ca0 0x18fb40088 0x18a1d8ffc 0x10008a264 0x19a0928b8) libc ++ abi.dylib:以NSException类型的未捕获异常终止

(Handle Swipes是函数的名称)

以下是代码:

导入UIKit

类Alabama1:UIViewController {     @IBOutlet弱var标签:UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

    let reveal = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes"))
    let next = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes"))

    // Do any additional setup after loading the view, typically from a nib.
    reveal.direction = .Up
    next.direction = .Left

    view.addGestureRecognizer(reveal)
    view.addGestureRecognizer(next)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func handleSwipes(sender:UISwipeGestureRecognizer) {
    if (sender.direction == .Up) {
        label.text = "Motgomery"
    }

}





}

2 个答案:

答案 0 :(得分:3)

您在添加活动时缺少分号。试试这样:

let reveal = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
let next = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))

答案 1 :(得分:1)

在swift3版本中:

   let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(MainMenuViewController.handleSwipes(_sender:)))