使用自定义 segue 对 begin/end 外观转换的不平衡调用
Unbalanced calls to begin/end appearance transitions with custom segue
在按下按钮时实现以下交叉溶解自定义转场(在 https://www.youtube.com/watch?v=xq9ZVsLNcWw 中学习):
override func perform() {
var src:UIViewController = self.sourceViewController as! UIViewController
var dstn:UIViewController = self.destinationViewController as! UIViewController
src.view.addSubview(dstn.view)
dstn.view.alpha = 0
UIView.animateWithDuration(0.75 , delay: 0.1, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: { () -> Void in
dstn.view.alpha = 1
}) { (finished) -> Void in
dstn.view.removeFromSuperview()
src.presentViewController(dstn, animated: false, completion: nil)
}
}
我得到 "Unbalanced calls to begin/end appearance transitions" warning/error.
我已经彻底搜索了很多Whosebug问题:
Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x197870>
- 我的回复:我将 segue 用作不在 TabBar 控制器内的按钮按下,因此此答案不适用
Keep getting "Unbalanced calls to begin/end appearance transitions for <ViewController>" error
- 我的回复:我尝试了两种方法:1) 所有转场都是用 self.performseguewithidentifier 编程完成的 2) 所有转场都是通过界面生成器完成的,通过单击拖动按钮并从属性窗格中选择我的自定义转换选择的segue。两者仍然产生上述错误。
"Unbalanced calls to begin/end appearance transitions" warning when push a view in a modal way in XCode 4 with Storyboard
- 我的回复:与上面相同,仔细检查所有 segues 仅以编程方式或通过界面构建器执行一次,而不是两者。
"Unbalanced calls to begin/end appearance transitions for DetailViewController" when pushing more than one detail view controller
- 我的回复:我没有在我的 segues 中使用 table 视图控制器或导航控制器,所以这个答案不适用。
Unbalanced calls to begin/end appearance transitions for UITabBarController
我的回复:我试着让所有的 segues 在调度中执行,如下所示
let delay = 0.01 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue()) {
self.performSegueWithIdentifier("toNonFBLogin", sender: nil)
}
然而仍然无济于事,warning/error 仍然弹出。
我知道这个错误是什么意思,它试图在加载前一个之前呈现一个新的 viewcontroller,但不确定如何解决它。
我唯一的线索是之前的(来源)viewcontroller 在最终 viewcontroller 加载之前快速弹出,如 0:04 处
所示
然而,我猜只有大约 5% 的时间出现故障。
有什么想法吗?
看起来这种行为是最近 iOS 版本中某些(到目前为止)未记录更改的结果。
对您的确切问题和缺乏令人满意的答案感到沮丧,我想出了这个:
// create a UIImageView containing a UIImage of `view`'s contents
func createMockView(view: UIView) -> UIImageView {
UIGraphicsBeginImageContextWithOptions(view.frame.size, true, UIScreen.mainScreen().scale)
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return UIImageView(image: image)
}
override func perform() {
let src:UIViewController = self.sourceViewController as! UIViewController
let dstn:UIViewController = self.destinationViewController as! UIViewController
let mock = createMockView(dstn.view)
src.view.addSubview(mock)
mock.alpha = 0
UIView.animateWithDuration(0.75, delay: 0.1, options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: { () -> Void in
mock.alpha = 1
},
completion: { (finished) -> Void in
src.presentViewController(dstn, animated: false, completion: { mock.removeFromSuperView()})
})
}
createMockView()
将创建一个 UIImageView
,其中包含目标 VC 内容的快照,并使用它来制作过渡动画。
一旦转换完成,真正的目的地 VC 将在没有动画的情况下呈现,从而导致两者之间的无缝转换。最后,一旦演示完成,模拟视图就会被删除。
在按下按钮时实现以下交叉溶解自定义转场(在 https://www.youtube.com/watch?v=xq9ZVsLNcWw 中学习):
override func perform() {
var src:UIViewController = self.sourceViewController as! UIViewController
var dstn:UIViewController = self.destinationViewController as! UIViewController
src.view.addSubview(dstn.view)
dstn.view.alpha = 0
UIView.animateWithDuration(0.75 , delay: 0.1, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: { () -> Void in
dstn.view.alpha = 1
}) { (finished) -> Void in
dstn.view.removeFromSuperview()
src.presentViewController(dstn, animated: false, completion: nil)
}
}
我得到 "Unbalanced calls to begin/end appearance transitions" warning/error.
我已经彻底搜索了很多Whosebug问题:
Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x197870>
- 我的回复:我将 segue 用作不在 TabBar 控制器内的按钮按下,因此此答案不适用
Keep getting "Unbalanced calls to begin/end appearance transitions for <ViewController>" error
- 我的回复:我尝试了两种方法:1) 所有转场都是用 self.performseguewithidentifier 编程完成的 2) 所有转场都是通过界面生成器完成的,通过单击拖动按钮并从属性窗格中选择我的自定义转换选择的segue。两者仍然产生上述错误。
"Unbalanced calls to begin/end appearance transitions" warning when push a view in a modal way in XCode 4 with Storyboard
- 我的回复:与上面相同,仔细检查所有 segues 仅以编程方式或通过界面构建器执行一次,而不是两者。
"Unbalanced calls to begin/end appearance transitions for DetailViewController" when pushing more than one detail view controller
- 我的回复:我没有在我的 segues 中使用 table 视图控制器或导航控制器,所以这个答案不适用。
Unbalanced calls to begin/end appearance transitions for UITabBarController
我的回复:我试着让所有的 segues 在调度中执行,如下所示
let delay = 0.01 * Double(NSEC_PER_SEC) let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) dispatch_after(time, dispatch_get_main_queue()) { self.performSegueWithIdentifier("toNonFBLogin", sender: nil) }
然而仍然无济于事,warning/error 仍然弹出。
我知道这个错误是什么意思,它试图在加载前一个之前呈现一个新的 viewcontroller,但不确定如何解决它。
我唯一的线索是之前的(来源)viewcontroller 在最终 viewcontroller 加载之前快速弹出,如 0:04 处
所示然而,我猜只有大约 5% 的时间出现故障。
有什么想法吗?
看起来这种行为是最近 iOS 版本中某些(到目前为止)未记录更改的结果。 对您的确切问题和缺乏令人满意的答案感到沮丧,我想出了这个:
// create a UIImageView containing a UIImage of `view`'s contents
func createMockView(view: UIView) -> UIImageView {
UIGraphicsBeginImageContextWithOptions(view.frame.size, true, UIScreen.mainScreen().scale)
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return UIImageView(image: image)
}
override func perform() {
let src:UIViewController = self.sourceViewController as! UIViewController
let dstn:UIViewController = self.destinationViewController as! UIViewController
let mock = createMockView(dstn.view)
src.view.addSubview(mock)
mock.alpha = 0
UIView.animateWithDuration(0.75, delay: 0.1, options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: { () -> Void in
mock.alpha = 1
},
completion: { (finished) -> Void in
src.presentViewController(dstn, animated: false, completion: { mock.removeFromSuperView()})
})
}
createMockView()
将创建一个 UIImageView
,其中包含目标 VC 内容的快照,并使用它来制作过渡动画。
一旦转换完成,真正的目的地 VC 将在没有动画的情况下呈现,从而导致两者之间的无缝转换。最后,一旦演示完成,模拟视图就会被删除。