滑动手势识别器 swift
Swipe gesture recognizer swift
我已经在互联网上搜索了几个小时,了解如何使用滑动手势识别器。我不想编写代码,因为我几乎尝试了每一个示例,但都行不通。但是,我知道对象库中有一个Swipe Gesture Recognizer,但是好像没有用。有人可以告诉我 link 到一个可以使用对象库中的滑动手势识别器的地方,或者告诉我如何做吗?
谢谢,
本
(如果我出于某种原因过于宽泛,或者您不喜欢我的问题,请不要 -1 这个,请发表评论,我会做出更改)。
崩溃日志:
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 是函数的名称)
代码如下:
导入 UIKit
class Alabama1: UIViewController {
@IBOutlet 弱变量标签: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"
}
}
}
您在添加事件时缺少分号。像这样尝试:
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:)))
我已经在互联网上搜索了几个小时,了解如何使用滑动手势识别器。我不想编写代码,因为我几乎尝试了每一个示例,但都行不通。但是,我知道对象库中有一个Swipe Gesture Recognizer,但是好像没有用。有人可以告诉我 link 到一个可以使用对象库中的滑动手势识别器的地方,或者告诉我如何做吗?
谢谢,
本
(如果我出于某种原因过于宽泛,或者您不喜欢我的问题,请不要 -1 这个,请发表评论,我会做出更改)。
崩溃日志: 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 是函数的名称)
代码如下:
导入 UIKit
class Alabama1: UIViewController { @IBOutlet 弱变量标签: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"
}
}
}
您在添加事件时缺少分号。像这样尝试:
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:)))