2012-09-16 86 views
2

我写了一个自定义UIStoryboardSegue,我正用它来在各种UIViewControllers之间转换。动画按需要工作,大部分时间显示为我在模拟器和设备上预期的那样。如何防止在自定义UIStoryboardSegue结束时出现“闪烁”的视图?

然而,SEGUE完成后,有时,我可以看到老UIViewController闪存一秒钟的UIStoryboardSegue完成后,一小部分。结果扰乱了我期待的平稳过渡。不幸的是,我无法辨别出这种行为的任何模式。

我已经包含了一个我正用来管理下面的segue的方法的准系统版本。有一种更可靠的方法来确保平稳过渡?难道我做错了什么?同样,大部分时间赛格看起来都是我想要的。

- (void)perform 
{ 
    self.window = [[[UIApplication sharedApplication] delegate] window]; 
    UIViewController *source = (UIViewController *) self.sourceViewController; 
    UIViewController *dest = (UIViewController *) self.destinationViewController; 

    [self.window insertSubview:dest.view.window belowSubview:source.view]; 

    self.segueLayer = [CALayer layer]; 
    // Create and add a number of other CALayers for displaying the segue, 
    // adding them to the base segueLayer 

    // Create and add CAAnimations for animating the CALayers 
    // (code omitted for the sake of space) 

    [self.window addSubview:dest.view]; 
    [self.window.layer addSublayer:self.segueLayer]; 

    [source.view removeFromSuperview]; 
} 

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)isFinished 
{ 
    UIViewController *source = (UIViewController *) self.sourceViewController; 
    UIViewController *dest = (UIViewController *) self.destinationViewController; 

    if (isFinished) 
    { 
     // Remove and deallocate the CALayers previously created 
     [self.segueLayer removeFromSuperlayer]; 
     self.segueLayer = nil; 
     self.window.rootViewController = dest; 
    } 
} 
+0

我正在尝试的一个建议是:为所有CAAnimation实例设置'removedOnCompletion = NO'和'fillMode = kCAFillModeForwards'。也许他们正在重置。 –

回答

2

所以CAAnimations不改变实际层的价值观,但那些与其相关的presentationLayer的。将fillMode设置为kCAFillModeForwards可确保在动画完成后presentationLayer的值不会恢复。但是,如果动画的removedOnCompletion属性设置为YES(默认情况下),该图层的外观也可以恢复到其预先动画状态。

由于animationDidStop:回调可能在任何潜在的逆转之后被调用,并且由于时序不准确,这可以解释为什么您不总能看到逆转。

+0

这个帐户对我来说似乎相当有说服力。我试着设置'removedOnCompletion = NO'和'fillMode = kCAFillModeForwards'并且还没有看到问题清单,我猜这是一个可能的解决方案。我会给它更多的测试。 –

+0

那么,我一遍又一遍地运行新代码,并没有看到任何问题。好极了! –