3
A
回答
4
我实现了一个赛格瑞“从左到右滑动”与定制赛格瑞和轻扫手势识别。
您需要创建一个新的.swift文件,并在界面构建器属性中将segue用作类。
// Created by David Seek on 25.04.16.
// Copyright © 2016 David Seek. All rights reserved.
//
import UIKit
class FromLeftToRightSegue: UIStoryboardSegue {
override func perform() {
let firstVC = self.sourceViewController.view as UIView!
let secondVC = self.destinationViewController.view as UIView!
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height
secondVC.frame = CGRectMake(-screenWidth, 0, screenWidth, screenHeight)
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVC, aboveSubview: firstVC)
// Animate the transition.
UIView.animateWithDuration(0.3, animations: {() -> Void in // set animation duration
firstVC.frame = CGRectOffset(firstVC.frame, 0.0, 0.0) // old screen stay
secondVC.frame = CGRectOffset(secondVC.frame, screenWidth, 0.0) // new screen strave from left to right
}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as UIViewController,
animated: false,
completion: nil)
}
}
}
轻扫手势识别器也需要进入一个新的.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
}
}
希望这对你有用,如果你有任何问题,请告诉我。
+0
哇是的这是我正在寻找的,谢谢你的帮助:) –
+0
非常欢迎 –
相关问题
- 1. hidesBarsOnSwipe禁用左右滑动手势
- 2. Android左右滑动手势处理
- 3. 在继续添加到UIView或UIViewController的滑动手势
- 4. 滑动手势滑动UIViews
- 5. 如何在执行拖动手势时平滑地生成CGAffineTransform
- 6. 所有方向的滑动手势(左,右,上,下)
- 7. 如何在android中通过手势轻松滑动?
- 8. 左手手势滑过UITextField
- 9. UITextView滑动手势
- 10. 滑动ios手势
- 11. 如何使左/右滑动手势更自由?
- 12. 如何在android中实现左右滑动手势。
- 13. 如何在UINavigationBar上禁用滑动右手势?
- 14. Android:如何处理从左到右的滑动手势
- 15. 闰盘 - 处理 - 滑动手势方向?
- 16. 平移手势和滑动手势
- 17. 如何通过UI测试执行“向左滑动”操作
- 18. 用手势滑动动画
- 19. Android手势检测器向上/向下滑动与左/右对齐
- 20. 如何拦截垂直滑动手势
- 21. 如何启用UITextView的滑动手势
- 22. SWRevealViewController如何删除滑动手势
- 23. 在ListView项上向右滑动手指
- 24. 添加滑动手势,无法滑动
- 25. 手柄向上轻扫,可向下滑动,向左滑动和向右滑动,即可手势在WinRT的应用
- 26. 如何捕获pageControl内部的tableView的横向滑动手势?
- 27. 如何处理ImageView上的向下滑动手势
- 28. 如何检测滑动手势的方向?
- 29. 如何实现UITableView向下滑动手势?
- 30. 滑动手势不工作
如果您只希望在用户从屏幕边缘滑动时发生segue,请查看[UIScreenEdgePanGestureRecognizer](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScreenEdgePanGestureRecognizer_class/# // apple_ref/OCC/instp/UIScreenEdgePanGestureRecognizer /边缘)。 –