gpt4 book ai didi

ios - 指定 "show"(推)segue 的方向

转载 作者:搜寻专家 更新时间:2023-10-30 21:55:26 24 4
gpt4 key购买 nike

是否有一种简单的方法来指定“显示”转场(以前称为“推”转场)的方向(从左、右、上或下)?

默认的“显示”转场从左到右,但我希望它从下到上。

最佳答案

我认为没有内置方法可以实现这一点,但是您可以使用 iOS7 中引入的自定义过渡。那里有很多很棒的教程,我在下面添加了一些链接和一些示例代码,演示了如何将新的 View Controller 从顶部向下滑动。

要检查的站点:

(注意:在第三和第四教程中访问UIViewControllerview的方式已经过时了。取而代之的是toViewController.view你应该使用 transitionContext.viewForKey(UITransitionContextToViewKey))

一个例子:

首先,您需要设置 Storyboard,我假设您已经完成了。

其次,您需要一个符合UIViewControllerAnimatedTransitioningNSObject 子类。这将用于控制从一个 View Controller 到下一个 View Controller 的转换。

class TransitionManager : NSObject, UIViewControllerAnimatedTransitioning {
let animationDuration = 0.5

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

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView()
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
containerView.addSubview(toView)

let finalFrame = containerView.bounds
let initalFrame = CGRect(x: 0, y: -finalFrame.height, width: finalFrame.width, height: finalFrame.height)

toView.frame = initalFrame
UIView.animateWithDuration(animationDuration,
animations: { toView.frame = finalFrame },
completion: { _ in transitionContext.completeTransition(true) })
}
}

RayWenderlich: How To Make A View Controller Transition Animation Like in the Ping App 中所述教程中,您需要设置 UINavigationController 的委托(delegate)。以下 NavigationControllerDelegate 类将用于在执行推送转场时返回 TransitionManager 的实例:

class NavigationControllerDelegate: NSObject, UINavigationControllerDelegate {
let transitionManager = TransitionManager()

func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
if operation == .Push {
return transitionManager
}

return nil
}
}

应该就是这样!要对此进行扩展,我建议您查看交互式过渡。

关于ios - 指定 "show"(推)segue 的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30551909/

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