我正在尝试在应用程序上创建交互式滑动过渡。
目标是当 View Controller 从底部拖动(而不是从底部边缘拖动,因此不会与控制中心冲突)时呈现一个 uiview,并将部分覆盖主视图 Controller (就像 iOS 一样)控制中心)。转换应该是交互式的,即根据用户的拖动。
很高兴听到有关可用 API 的想法。
最佳答案
以下代码将执行在 Xcode 8 中测试并有效的简单幻灯片 View 动画代码。
import UIKit
class ViewController: UIViewController,UIGestureRecognizerDelegate {
// I am using VisualView as a slideView
@IBOutlet weak var slideView: UIVisualEffectView!
//Button to open slideView
@IBOutlet weak var button: UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// setting background for sideView
slideView.backgroundColor = UIColor(patternImage: UIImage(named: "original.jpg")!)
//Initial hide so it won't show.when the mainView loads...
slideView.isHidden = true
// DownSwipe to hide slideView
let downSwipe = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.handleSwipes(_:)))
downSwipe.direction = .down
view.addGestureRecognizer(downSwipe)
}
// set UIButton to open slideVie...(I am using UIBarButton)
@IBAction func sdrawButton(_ sender: AnyObject) {
self.slideView.isHidden = false
slideView.center.y += view.frame.height
UIView.animate(withDuration: 0.7, delay: 0, options: UIViewAnimationOptions.curveEaseIn, animations:{
self.slideView.center.y -= self.view.frame.height
self.button.isEnabled = false
}, completion: nil)
}
func handleSwipes(_ sender:UISwipeGestureRecognizer) {
if (sender.direction == .down) {
print("Swipe Down")
self.slideView.isHidden = true
self.slideView.center.y -= self.view.frame.height
UIView.animate(withDuration: 0.7, delay: 0, options: UIViewAnimationOptions.curveEaseOut, animations:{
self.slideView.center.y += self.view.frame.height
self.button.isEnabled = true
}, completion: nil)
}
}
}
让我知道该代码适合您...
关于swift - Swift 中类似控制中心的滑动 View 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39875306/