ios - 如何进行自定义 View Controller 转换,其中一部分是 UIView animateWithDuration 而另一部分是 transitionFromView?

标签 ios objective-c cocoa-touch ios7 uiviewcontroller

我似乎无法弄清楚如何同时执行 animateWithDurationtransitionWithView在 iOS 7 中使用自定义 View Controller 转换。

这是我转换 View 的代码。我基本上想从初始 View (表示为屏幕截图)过渡到使其模糊和变暗(我将初始屏幕截图图像溶解为模糊图像并在其上添加一个深色透明 View ):

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    ImageGalleryPageViewController* toViewController = (ImageGalleryPageViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    // Add an image view representing the view controller we're transitioning from
    UIImage *fromVCImage = [self convertViewToImage:fromViewController.view];
    UIImageView *fromVCImageView = [[UIImageView alloc] initWithImage:fromVCImage];

    [[transitionContext containerView] addSubview:fromVCImageView];

    // Create a blurred version of the same image view
    GPUImageiOSBlurFilter *blurFilter = [[GPUImageiOSBlurFilter alloc] init];
    blurFilter.blurRadiusInPixels = 2.0;

    UIImage *blurredFromVCImage = [blurFilter imageByFilteringImage:fromVCImage];
    UIImageView *blurredFromVCImageView = [[UIImageView alloc] initWithImage:blurredFromVCImage];

    // Add a dark overlay
    UIView *darkOverlay = [[UIView alloc] initWithFrame:fromVCImageView.frame];
    darkOverlay.backgroundColor = [UIColor blackColor];
    darkOverlay.alpha = 0.0;

    [[transitionContext containerView] addSubview:darkOverlay];

    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        darkOverlay.alpha = 0.8;
    } completion:^(BOOL finished) {
    }];

    [UIView transitionFromView:fromVCImageView toView:blurredFromVCImageView duration:[self transitionDuration:transitionContext] options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    }];
}

但只有模糊部分有效,变暗无效。如果我删除最后一个 block 并只保留第一个 block ,那么变暗效果很好。我似乎不能两者兼得。

我怎样才能让它们都工作?我知道可能有一种解决方法可以调整模糊图像的 alpha,但我想使用 transitionFromView:以获得更高级的效果。

最佳答案

transitionWithView:... , 逻辑或 UIViewAnimationOptionBeginFromCurrentState作为您的选择之一。否则,由于另一个动画刚刚开始,深色叠加动画会突然结束。包含此选项会告诉下一个动画从上一个动画的当前状态开始。

关于ios - 如何进行自定义 View Controller 转换,其中一部分是 UIView animateWithDuration 而另一部分是 transitionFromView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23924675/

相关文章:

ios - 当数据在两个字典中时,如何区分数据和json?

iphone - App Store Review,启用登录的应用程序?

objective-c - 自动将 View 放置在下一个逻辑位置(如布局管理器)

objective-c - 使用 QLPreviewController/UIWebView 预览具有合并字段的 Word 文档

ios - 如何在单独的动画中将 CGAffineTransform 链接在一起?

objective-c - 设置 UINavigationBar 的标题

iphone - UITextView 上的 resignFirstResponder - 减缓键盘消失

ios - ios中如何用核心数据提高大数据导入性能

ios - 播放声音和动画

ios - 如何在 iOS 中使用 NSUserDafaults 保存和检索 NSObject 类