我编写了一个自定义 UIStoryboardSegue
,用于在各种 UIViewControllers
之间进行转换。动画按预期工作,并且大多数时候 UIStoryboardSegue
在模拟器和设备上都按照我的预期显示。
但是,有时在 Segue 完成后,我可以在 UIStoryboardSegue
完成后的几分之一秒内看到旧的 UIViewController
flash。结果破坏了我所期待的平稳过渡。不幸的是,我无法辨别这种行为的任何模式。
我已经包含了我用来管理下面的 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;
}
}
最佳答案
因此 CAAnimations 不会更改实际图层的值,而是更改其关联的 presentationLayer
的值。将 fillMode
设置为 kCAFillModeForwards
可确保 presentationLayer
的值在动画完成后不会恢复。但是,如果动画的 removedOnCompletion
属性设置为 YES
(默认情况下),图层的外观也可以恢复到动画前的状态。
由于 animationDidStop:
回调可能会在任何潜在的还原之后被调用,并且由于时间不准确,这可以解释为什么您并不总是看到还原。
关于ios - 如何阻止自定义 UIStoryboardSegue 末尾的 "flashing" View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443671/