使用滑动手势更改视图
Changing views with swipe gesture
我已经尽可能多地在谷歌上搜索以尝试找到它。一般来说,我是应用程序开发和编程的新手。我想通过滑动手势查看 return 到上一个视图。
这是我的ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var changeView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeDown:")
recognizer.direction = .Down
self.view .addGestureRecognizer(recognizer)
func swipeDown(recognizer : UISwipeGestureRecognizer) {
self.performSegueWithIdentifier("HowToPlaySegue", sender: self)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
现在我也是新 Xcode 的初学者。如果我没记错的话,手势过去就像按钮一样,只需简单地控制拖动到视图就可以了。
在xcode我有我想滑动的视图,我有主视图。我做错了什么?
我现在收到错误。现在我的 AppDelegate.swift 还没有被触及。我相信这就是我的选择器的去向,但我不确定,而且我找不到太多关于这个特定的东西。
[Swipe_t.ViewController swipeDown:]: unrecognized selector sent to instance 0x7fe94bc7a080
2015-03-05 23:10:15.637 Swipe't[32779:3391684] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swipe_t.ViewController swipeDown:]: unrecognized selector sent to instance
1) 您的 swipeDown
函数在 viewDidLoad
中。那不应该在 viewDidLoad 大括号之外吗?
编辑(添加修改后的代码)
override func viewDidLoad()
{
super.viewDidLoad()
let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeDown:")
recognizer.direction = .Down
self.view.addGestureRecognizer(recognizer)
}
func swipeDown(recognizer : UISwipeGestureRecognizer)
{
self.performSegueWithIdentifier("HowToPlaySegue", sender: self)
}
2) 其次,虽然我不确定你的用例,但根据你提供的信息,我认为你可以利用 UIPageViewController。无需自己实现滑动行为。
我已经尽可能多地在谷歌上搜索以尝试找到它。一般来说,我是应用程序开发和编程的新手。我想通过滑动手势查看 return 到上一个视图。
这是我的ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var changeView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeDown:")
recognizer.direction = .Down
self.view .addGestureRecognizer(recognizer)
func swipeDown(recognizer : UISwipeGestureRecognizer) {
self.performSegueWithIdentifier("HowToPlaySegue", sender: self)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
现在我也是新 Xcode 的初学者。如果我没记错的话,手势过去就像按钮一样,只需简单地控制拖动到视图就可以了。
在xcode我有我想滑动的视图,我有主视图。我做错了什么?
我现在收到错误。现在我的 AppDelegate.swift 还没有被触及。我相信这就是我的选择器的去向,但我不确定,而且我找不到太多关于这个特定的东西。
[Swipe_t.ViewController swipeDown:]: unrecognized selector sent to instance 0x7fe94bc7a080 2015-03-05 23:10:15.637 Swipe't[32779:3391684] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swipe_t.ViewController swipeDown:]: unrecognized selector sent to instance
1) 您的 swipeDown
函数在 viewDidLoad
中。那不应该在 viewDidLoad 大括号之外吗?
编辑(添加修改后的代码)
override func viewDidLoad()
{
super.viewDidLoad()
let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeDown:")
recognizer.direction = .Down
self.view.addGestureRecognizer(recognizer)
}
func swipeDown(recognizer : UISwipeGestureRecognizer)
{
self.performSegueWithIdentifier("HowToPlaySegue", sender: self)
}
2) 其次,虽然我不确定你的用例,但根据你提供的信息,我认为你可以利用 UIPageViewController。无需自己实现滑动行为。