使用自定义转场开始/结束外观过渡的不平衡调用 [英] Unbalanced calls to begin/end appearance transitions with custom segue

查看:29
本文介绍了使用自定义转场开始/结束外观过渡的不平衡调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在按下按钮时实现以下交叉溶解自定义转场(在 https://www.youtube.com/watch?v=xq9ZVsLNcWw):

In implementing the following cross-dissolve custom segue on a button press (learned at 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)

    }

}

我收到开始/结束外观转换的调用不平衡"警告/错误.

I am getting the "Unbalanced calls to begin/end appearance transitions" warning/error.

我已经彻底搜索了许多 stackoverflow 问题:

I have thoroughly searched many stackoverflow questions:

开始/结束外观过渡的不平衡调用<UITabBarController: 0x197870>

  • 我的回答:我使用 segue 作为按钮按下而不是在 TabBar 控制器中,所以这个答案不适用

不断收到不平衡的调用"<ViewController>"的开始/结束外观转换错误

  • 我的回答:我尝试了两种方法:1) 使用 self.performseguewithidentifier 以编程方式完成所有转场 2) 通过界面构建​​器完成所有转场,方法是单击拖动按钮并从所选转场的属性窗格中选择我的自定义转换.两者仍然产生上述错误.

"开始/结束外观转换的不平衡调用"在带有 Storyboard 的 XCode 4 中以模态方式推送视图时发出警告

  • 我的回答:与上述相同,以编程方式或通过界面构建​​器,两次检查所有 segue 仅执行一次,不能同时执行.

不平衡调用开始/结束外观转换DetailViewController"推送多个细节视图控制器时

  • 我的回答:我没有在 segue 中使用表视图控制器或导航控制器,因此此答案不适用.

UITabBarController 开始/结束外观转换的不平衡调用

  • 我的回答:我尝试让所有 segue 在一个 dispatch 中执行,如下所示

  • my response: I tried making all segues perform within a dispatch as shown below

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)

 }

然而仍然无济于事,警告/错误仍然弹出.

however still to no avail, the warning/error still pops up.

我知道错误意味着什么,它试图在前一个加载之前呈现一个新的视图控制器,但不知道如何解决它.

I'm aware what the error means, that it's attempting to present a new viewcontroller before the previous one loads, but not sure how to tackle it.

我唯一的线索是前一个(源)视图控制器在最终视图控制器加载之前快速弹出,如

The only lead I have is that the previous (source) viewcontroller pops up real quickly before the final viewcontroller loads, as seen at 0:04 at

https://youtu.be/i1D5fbcjNjY

不过,我猜大概只有 5% 的时间会出现故障.

The glitch only actually appears I would guess around 5% of the time, however.

有什么想法吗?

推荐答案

看起来这种行为是最近 iOS 版本中一些 - 迄今为止 - 未记录的更改的结果.对您的确切问题感到沮丧,并且缺乏令人满意的答案,我想出了这个:

Looks like this behaviour is the result of some - as of yet - undocumented change in recent iOS releases. Getting frustrated with your exact issue and the lack of satisfying answers I've come up with this:

// 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,没有动画会导致两者之间的无缝过渡.最后,演示完成后,模拟视图将被删除.

createMockView() will create a UIImageView containing a snapshot of the destination VCs contents and use that to do the transition animation. Once the transition is finished the real destination VC is presented without animation causing a seamless transition between both. Finally once the presentation is done the mock view is removed.

这篇关于使用自定义转场开始/结束外观过渡的不平衡调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆