gpt4 book ai didi

ios - 自定义 UIStoryboardSegue - UIViewController 支持的InterfaceOrientations 从不调用

转载 作者:行者123 更新时间:2023-11-30 13:39:04 27 4
gpt4 key购买 nike

我在创建自定义转场时遇到问题:我正在重写“perform()”方法,如下所示

override func perform() {
if !isBack {
self.destinationViewController.view.frame = CGRectMake(self.sourceViewController.view.frame.width, 0, self.sourceViewController.view.frame.width, self.sourceViewController.view.frame.height)
self.sourceViewController.view.addSubview(self.destinationViewController.view)
self.sourceViewController.addChildViewController(self.destinationViewController)
print("Source: \(self.sourceViewController) ---> Destination: \(self.destinationViewController)")
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.destinationViewController.view.frame = CGRectMake(0, 0, self.destinationViewController.view.frame.width, self.destinationViewController.view.frame.height)
}, completion: { (bolean) -> Void in
print("Animation Completed")
})

}else{
print("Source: \(self.sourceViewController) ---> Destination: \(self.destinationViewController)")
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.sourceViewController.view.frame = CGRectMake(self.sourceViewController.view.frame.width, 0, self.sourceViewController.view.frame.width, self.sourceViewController.view.frame.height)
}, completion: { (bolean) -> Void in
print("Animation Completed")

self.sourceViewController.view.removeFromSuperview()
})
}

一切运行正常,但此时,“destinationViewController”中的旋转方法尚未被调用。因此,如果我将“sourceViewController”锁定为纵向模式,同时保持“destinationViewController”解锁,则后者不会旋转。

假设问题出在这一行:self.sourceViewController.view.addSubview(self.destinationViewController.view)我应该如何更改代码来修复旋转?

最佳答案

好吧,我已经找到了这样的解决方案。

override func perform() {
if !isBack {
self.destinationViewController.view.frame = CGRectMake(self.sourceViewController.view.frame.width, 0, self.sourceViewController.view.frame.width, self.sourceViewController.view.frame.height)

let window = UIApplication.sharedApplication().keyWindow
window?.insertSubview(self.destinationViewController.view, aboveSubview: self.sourceViewController.view)

print("Source: \(self.sourceViewController) ---> Destination: \(self.destinationViewController)")
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.destinationViewController.view.frame = CGRectMake(0, 0, self.destinationViewController.view.frame.width, self.destinationViewController.view.frame.height)
}, completion: { (bolean) -> Void in
print("Animazione Terminata")
self.sourceViewController.presentViewController(self.destinationViewController, animated: false, completion: nil)
})

}else{
print("Indietro Source: \(self.sourceViewController) ---> Destination: \(self.destinationViewController)")

let snapshot = self.sourceViewController.view.snapshotViewAfterScreenUpdates(false)
snapshot.frame = CGRectMake(0, 0, snapshot.frame.size.width, snapshot.frame.size.height)
self.destinationViewController.view.addSubview(snapshot)
self.sourceViewController.dismissViewControllerAnimated(false, completion: nil)
dispatch_async(dispatch_get_main_queue(), { () -> Void in
UIView.animateWithDuration(0.5, animations: { () -> Void in
snapshot.frame = CGRectMake(self.destinationViewController.view.frame.width, 0, self.destinationViewController.view.frame.width, self.destinationViewController.view.frame.height)
}, completion: { (bolean) -> Void in
print("Animazione Terminata")
snapshot.removeFromSuperview()
})
})
}
}

我已经明白 UIStoryboar 最终会像演示文稿一样执行相同的操作。所以在你必须创建动画之前,然后呈现。当您需要在获取屏幕快照之前关闭时,关闭不带动画的源 VC(在关闭之前在目标 VC 中添加快照)并最终为快照设置动画。

tnx 并购买。

抱歉我的英语不好,但谈话就是芯片,我展示了代码。

编辑:我的代码有点不精确。为了防止动画问题,只需在当前状态中设置或关闭动画即可。

关于ios - 自定义 UIStoryboardSegue - UIViewController 支持的InterfaceOrientations 从不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35780069/

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