gpt4 book ai didi

ios - UIView 没有持续时间的动画

转载 作者:行者123 更新时间:2023-11-30 14:10:45 25 4
gpt4 key购买 nike

滑动时,我希望在页面之间平滑导航(根据手指移动而变化),而不是在给定时间内导航

class FirstCustomSegue: UIStoryboardSegue {
override func perform() {
// Assign the source and destination views to local variables.
var firstVCView = self.sourceViewController.view as UIView!
var secondVCView = self.destinationViewController.view as UIView!

// Get the screen width and height.
let screenWidth = UIScreen.mainScreen().bounds.size.width
let screenHeight = UIScreen.mainScreen().bounds.size.height

// Specify the initial position of the destination view.
secondVCView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight)

// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(secondVCView, aboveSubview: firstVCView)

// Animate the transition.
UIView.animateWithDuration(0.4, animations: { () -> Void in
firstVCView.frame = CGRectOffset(firstVCView.frame, -screenWidth, 0.0)
secondVCView.frame = CGRectOffset(secondVCView.frame, -screenWidth, 0.0)

}) { (Finished) -> Void in
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController,
animated: false,
completion: nil)
}
} }

最佳答案

我最近不得不处理这个问题。看看我的github project ,也许会对你有帮助。

简单来说。您应该创建类采用

UIViewControllerAnimatedTransitioning

并实现2个方法。一个用于动画的持续时间,另一个用于自定义动画(移动、淡入淡出等)。

例如:

class ModalPresentAnimationController: NSObject, UIViewControllerAnimatedTransitioning {

func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.5
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)!
// ...
let duration = transitionDuration(transitionContext)
UIView.animateWithDuration(duration, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.2, options: UIViewAnimationOptions.CurveLinear, animations: {
toVC.view.frame = // new postion
}) { finished in

transitionContext.completeTransition(!transitionContext.transitionWasCancelled())
}
}

然后在你的ViewController中指定一个新的ViewControllerTransitioning

extension ViewController: UIViewControllerTransitioningDelegate {

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
swipeInteractionController.wireToViewController(presented)
return modalPresentAnimationController
}

但是,如果你想添加“根据手指移动而变化”,你应该创建类采用

UIPercentDrivenInteractiveTransition

并在其中使用gestureRecognizer。

关于ios - UIView 没有持续时间的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31805838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com