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 /邊緣)。 –