gpt4 book ai didi

ios - 如果未设置为初始窗口,则自定义 Segue 不起作用

转载 作者:行者123 更新时间:2023-11-28 09:01:49 25 4
gpt4 key购买 nike

以下是 Swift 中自定义 segue 动画的代码摘录,仅当我将源 viewController 作为 Storyboard 中的初始窗口时,它才能正常工作。

class CustomSegue: UIStoryboardSegue
{
override func perform()
{
var fromView = self.sourceViewController.view as UIView!
var toView = self.destinationViewController.view as UIView!

let offScreenHorizontalStart = CGAffineTransformMakeRotation(CGFloat(M_PI / 2))
let offScreenHorizontalEnd = CGAffineTransformMakeRotation(CGFloat(-M_PI / 2))

fromView.layer.anchorPoint = CGPoint(x:0, y:0)
fromView.layer.position = CGPoint(x:0, y:0)

UIApplication.sharedApplication().keyWindow?.insertSubview(toView, belowSubview: fromView)

UIView.animateWithDuration(0.7, delay: 0.0, usingSpringWithDamping: 1.6, initialSpringVelocity: 0.0, options: nil, animations:
{
fromView.transform = offScreenHorizontalEnd
}, completion: {
finished in
self.sourceViewController.presentViewController(self.destinationViewController as! UIViewController, animated: false, completion: nil)
})
}
}

通过这个 segue 动画,源 View 预计会随着 x/y = 0/0 的向上旋转而消失。

谢谢。

最佳答案

就您在此处显式使用 UIApplication 对象的 keyWindow 属性而言:

UIApplication.sharedApplication().keyWindow?.insertSubview(toView, belowSubview: fromView)

我认为它不适用于其他窗口也就不足为奇了。

您可以改用 UIApplicationwindows 属性。它以有序的 NSArray(数组中的最后一个对象是最顶层的窗口)保存应用程序中当前打开的所有 UIWindow 对象。或者您从 fromView.window 属性中选择当前窗口?

关于ios - 如果未设置为初始窗口,则自定义 Segue 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31805094/

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