Md *_*man 6 swipe ios swift swift3 xcode8
我想使用滑动手势在我的标签栏之间导航.最简单的方法是什么?我试过这样的事......
import UIKit
class postAdViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
var leftSwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
view.addGestureRecognizer(leftSwipe)
}
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .left) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "favourireviewcontroller") as! UIViewController
self.present(vc, animated: true, completion: nil)
}
if (sender.direction == .right) {
}
}
Run Code Online (Sandbox Code Playgroud)
如果我试图向右滑动没有任何反应.滑动时,应用程序崩溃以下错误消息
无法识别的选择器发送到实例0x7f924380a730
尝试使用Swift 3
选择器语法:
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:))
Run Code Online (Sandbox Code Playgroud)
像这样
override func viewDidLoad() {
super.viewDidLoad()
nextButton.layer.cornerRadius = 7
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:))
//leftSwipe.direction = .right
view.addGestureRecognizer(leftSwipe)
}
func handleSwipes(_ sender: UISwipeGestureRecognizer) {
if (sender.direction == .left) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "favourireviewcontroller") as! UIViewController
self.present(vc, animated: true, completion: nil)
}
if (sender.direction == .right) {
}
}
Run Code Online (Sandbox Code Playgroud)
Swift 3
引入此功能是为了使编译器能够检查function
您指定的是否确实存在。因此,它比以前的概念要节省得多。
归档时间: |
|
查看次数: |
7218 次 |
最近记录: |