简体   繁体   English

在视图控制器之间滑动手势

[英]Swipe gesture between view controllers

I am trying to create a swipe on background. 我正在尝试在背景上创建一个滑动。 I have three different color of backgrounds. 我有三种不同颜色的背景。 I have made a button and when I click my button my background changes to next scene. 我做了一个按钮,当我点击我的按钮时,我的背景变为下一个场景。 I want to change this and I want to swipe my thumb left or right to change the background and not to have to click on the button. 我想改变这个,我想向左或向右滑动我的拇指来改变背景而不必点击按钮。 How would I achieve that. 我怎么做到这一点。

here are some more details 这里有一些更多的细节

my view controller is 我的视图控制器是

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

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


}

在此输入图像描述

Swift version: Swift版本:

Add gesture recognizer: 添加手势识别器:

override func viewDidLoad() {
    super.viewDidLoad()
    let recognizer: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeLeft:")
    recognizer.direction = .Left
    self.view .addGestureRecognizer(recognizer)
}

action function: 动作功能:

func swipeLeft(recognizer : UISwipeGestureRecognizer) {
    self.performSegueWithIdentifier("MySegue", sender: self)
}

Ok, So I figured it out. 好的,我明白了。 Xcode has swipe gesture in its right panel and it was as same as dropping the button in the view. Xcode在右侧面板中有滑动手势,就像在视图中删除按钮一样。 Only difference is that it shows up on the top instead of inside the view. 唯一的区别是它显示在顶部而不是在视图内部。 So after I figured that it was as easy as holding the ctrl button and dragging it to another view and voilla it worked. 所以在我认为它就像握住ctrl按钮并将其拖动到另一个视图一样简单并且它有效。 Below are some images for some people if they stumble upon this: 以下是一些人偶然发现的一些图片:

在此输入图像描述

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM