ios - 如何阻止自定义 UIStoryboardSegue 末尾的 "flashing" View ?

标签 ios objective-c ios5 uistoryboardsegue

我编写了一个自定义 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/

相关文章:

ios - 如何删除 CKRecord 中的键和对象?

ios - Objective-c 中数组中的 Swift 闭包变为 nil

ios - 带有 UIWebView 的动态 UITableViewCell

ios - 将 Swift String 转换为 UTF-8 并使用 char 的 ASCII 值进行算术运算

iphone - 在接口(interface)文件 : when to use forward declaration for custom class as opposed to just including its header?

ios - 如何在XIB(Interface Builder)中使用UIPageViewController的子类来设置DataSource、Delegate和TransitionStyle

ios - 蓝牙通信 NSStream 是否应该需要一个单独的线程?

ios5 - 如何从 iOS 上的播放列表播放歌曲(仅歌曲)?

ios - 当 1 根手指在屏幕上抬起时禁用捏合识别器

ios - SWIFT 中类似于 UIColor.systemgray 的任何标准字符串