Swift 如何使用向右滑动的手势执行连续动作
我想做一个右击的姿势来完成一个序列Swift 如何使用向右滑动的手势执行连续动作,swift,swipe,collectionview,Swift,Swipe,Collectionview,我想做一个右击的姿势来完成一个序列 最佳实践是什么?我正在实现一个带有自定义segue和滑动手势识别器的“从左向右滑动”的segue 您需要创建一个新的.swift文件,并在interface builder属性中使用segue as类 刷卡手势识别器还需要输入一个新的.swift文件: import Foundation import UIKit // // UISwipeGestureRecognizer.h // UIKit // // Copyright (c) 2009-2
最佳实践是什么?我正在实现一个带有自定义segue和滑动手势识别器的“从左向右滑动”的segue 您需要创建一个新的.swift文件,并在interface builder属性中使用segue as类 刷卡手势识别器还需要输入一个新的.swift文件:
import Foundation
import UIKit
//
// UISwipeGestureRecognizer.h
// UIKit
//
// Copyright (c) 2009-2015 Apple Inc. All rights reserved.
//
// Recognizes: when numberOfTouchesRequired have moved mostly in the specified direction, enough to be considered a swipe.
// a slow swipe requires high directional precision but a small distance
// a fast swipe requires low directional precision but a large distance
// Touch Location Behaviors:
// locationInView: location where the swipe began. this is the centroid if more than one touch was involved
// locationOfTouch:inView: location of a particular touch when the swipe began
public struct UISwipeGestureRecognizerDirection : OptionSetType {
public init(rawValue: UInt)
public static var Right: UISwipeGestureRecognizerDirection { get }
public static var Left: UISwipeGestureRecognizerDirection { get }
public static var Up: UISwipeGestureRecognizerDirection { get }
public static var Down: UISwipeGestureRecognizerDirection { get }
}
@available(iOS 3.2, *)
public class UISwipeGestureRecognizer : UIGestureRecognizer {
public var numberOfTouchesRequired: Int // default is 1. the number of fingers that must swipe
public var direction: UISwipeGestureRecognizerDirection // default is UISwipeGestureRecognizerDirectionRight. the desired direction of the swipe. multiple directions may be specified if they will result in the same behavior (for example, UITableView swipe delete)
}
通过以下方式在所需的ViewController.swift内调用:
private var swipeGestureRecognizer: UISwipeGestureRecognizer?
override func viewDidLoad() {
super.viewDidLoad()
swipeGestureRecognizer = MySwipeGestureRecognizer(target: self, swipeLeftSegue: "yourSwipeLeftSegue", swipeRightSeque: "yourSwipeRightSegue")
view.addGestureRecognizer(swipeGestureRecognizer!)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "yourSwipeLeftSegue" {
//your code goes here
}
}
希望这对您有用,如果您有任何问题,请告诉我。如果您只希望在用户从屏幕边缘滑动时发生这种情况,请查看。哇,是的,这正是我要找的,谢谢您的帮助:)
private var swipeGestureRecognizer: UISwipeGestureRecognizer?
override func viewDidLoad() {
super.viewDidLoad()
swipeGestureRecognizer = MySwipeGestureRecognizer(target: self, swipeLeftSegue: "yourSwipeLeftSegue", swipeRightSeque: "yourSwipeRightSegue")
view.addGestureRecognizer(swipeGestureRecognizer!)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "yourSwipeLeftSegue" {
//your code goes here
}
}