I have a UIViewController I'm presenting using a custom transition (for blurring). When I press the close button, I want the UIViewController to fade out. I reduce the opacity of the view and it fades out fine. And in the completion block, I dismiss the UIViewController. It gets dismissed, but there's a flicker soon after the dismiss is done and over with.

Here's what I'm doing:

- (IBAction)closePressed:(id)sender {

    [CATransaction setCompletionBlock:^{
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
    CABasicAnimation *fadeOut = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fadeOut.fromValue = [NSNumber numberWithFloat:1.0];
    fadeOut.toValue = [NSNumber numberWithFloat:0.0];
    fadeOut.duration = 0.4f;
    [self.view.layer addAnimation:fadeOut forKey:@"fadeOut"];
}

Can't paste a screenshot or anything as it happens quickly. There's a flicker before the parent UIViewController is shown.

有帮助吗?

解决方案

When you animate via CAAnimation you are actually animating the presentation layer of the view, not the actual view. So when animation ends, you'll end up with the view as it was before the animation started.

To avoid that add this two lines before addAnimation:forKey:

fadeOut.removedOnCompletion = NO;
fadeOut.fillMode = kCAFillModeForwards;

其他提示

Have you tried as like below?

[UIView animateWithDuration:0.4 animations:^
    {
       self.view.alpha = 0.0;

    } completion:^(BOOL finished)
    {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];

Instead of above method, You can use self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

Try switching your opaque setting for that viewcontroller to YES / NO

Default value is YES, so you probably want to try out NO

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top