[英]Swipe gesture recognizer swift
I have been looking on the internet for a few hours now on how to use the Swipe Gesture Recognizer. 我已经在互联网上搜索了几个小时,以了解如何使用“滑动手势识别器”。 I do not want to code it, because I have tried nearly every single example and that doesn't work.
我不想编写代码,因为我已经尝试了几乎每个示例,但都行不通。 However, I know that there is a Swipe Gesture Recognizer in the object library, but it doesn't seem to work.
但是,我知道对象库中有一个“滑动手势识别器”,但是它似乎不起作用。 Can somebody please show me a link to a place where I can use the Swipe Gesture Recognizer from the Object Library or show me how to do it?
有人可以给我显示指向我可以使用“对象库”中的“滑动手势识别器”的地方的链接,或者向我显示如何做的地方吗?
Thanks, 谢谢,
Ben 本
(If I am being to broad for some reason, or you don't like my question, please do not -1 this, just comment and I will make the change, please). (如果我出于某种原因而宽泛,或者您不喜欢我的问题,请不要将此设为-1,请发表评论,然后我进行更改)。
Crash Log: 2016-01-09 10:59:33.392 Capitals[250:14059] -[Capitals.Alabama1 handleSwipes]: unrecognized selector sent to instance 0x14f695150 2016-01-09 10:59:33.397 Capitals[250:14059] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Capitals.Alabama1 handleSwipes]: unrecognized selector sent to instance 0x14f695150' * First throw call stack: (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: terminating with uncaught exception of type NSException 崩溃日志:2016-01-09 10:59:33.392 Capitals [250:14059]-[Capitals.Alabama1 handleSwipes]:无法识别的选择器已发送到实例0x14f695150 2016-01-09 10:59:33.397 Capitals [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 is the name of the function) (Handle Swipes是函数的名称)
Here is the code: 这是代码:
import UIKit 导入UIKit
class Alabama1: UIViewController { @IBOutlet weak var label: UILabel! 类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"
}
}
}
You are missing semicolumn in adding event. 您在添加事件中缺少分号。 Try like so:
尝试这样:
let reveal = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
let next = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
在swift3版本中:
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(MainMenuViewController.handleSwipes(_sender:)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.