iOS 10中的UIVisualEffectView [英] UIVisualEffectView in iOS 10

查看:787
本文介绍了iOS 10中的UIVisualEffectView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在呈现一个包含UIVisualEffectView的UIViewController,如下所示:

I am presenting a UIViewController that contains a UIVisualEffectView as follows:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self performSegueWithIdentifier:@"segueBlur" sender:nil];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if([segue.identifier isEqualToString:@"segueBlur"]) {
        ((UIViewController *)segue.destinationViewController).providesPresentationContextTransitionStyle = YES;
        ((UIViewController *)segue.destinationViewController).definesPresentationContext = YES;
        ((UIViewController *)segue.destinationViewController).modalPresentationStyle = UIModalPresentationOverFullScreen;
    }
}

如你所见,我正在使用UIModalPresentationStyleOverFullScreen这样当模糊的视图控制器出现时,模糊将应用到呈现它的视图控制器的内容; segue具有Cross Dissolve过渡样式。

As you can see, I'm using the UIModalPresentationStyleOverFullScreen so that when the view controller with blur appears, the blur will be 'applied' to the content of the view controller that is presenting it; the segue has a Cross Dissolve transition style.

效果看起来像预期的那样。但是,在iOS 9中,演示比iOS 10更流畅。在iOS 10中,当视图控制器出现时,它看起来像是两步动画,而在iOS 9中,模糊立即应用。

The effect looks as expected. However, in iOS 9 the presentation is smoother than in iOS 10. In iOS 10 when the view controller appears it seems like a 2-step animation, while in iOS 9 the blur is applied immediately.

一张图片胜过千言万语所以我上传了一段显示这种奇怪行为的视频:

A picture is worth a thousand words so I uploaded a video showing this strange behavior:

UIVisualEffectView iOS 9 vs iOS 10

我的问题是:如何在iOS 10中呈现视图控制器为它出现在iOS 9中?

My question is: How can I present the view controller in iOS 10 as it is presented in iOS 9?

推荐答案

iOS 10改变了方式 UIVisualEffectView 工作,它已经打破了许多用例,这些用例并非严格意义上的合法,而是之前的工作。坚持使用文档,你不应该在 UIVisualEffectView 中消失,这就是使用 UIModalTransitionStyleCrossDissolve 时会发生的情况。它现在似乎在iOS 10上被破坏,同时屏蔽了视觉效果视图和其他视图。

iOS 10 has changed the way UIVisualEffectView works, and it has broken many use cases which were not strictly speaking "legal", but worked before. Sticking to documentation, you should not be fading in UIVisualEffectView, which is what happens when you use UIModalTransitionStyleCrossDissolve. It seems now broken on iOS 10, along with masking of visual effect views, and others.

在你的情况下,我建议一个简单的修复,这也将创造一个更好的效果比以前好,并且在iOS 9和10上都受支持。创建自定义演示文稿而不是淡入视图,从效果属性设置动画nil 到模糊效果。如果需要,您可以淡入视图层次结构的其余部分。这样可以巧妙地为模糊半径设置动画,类似于向下拉主屏幕图标时的外观。

In your case, I would suggest an easy fix which will also create a better effect than before, and is supported on both iOS 9 and 10. Create a custom presentation and instead of fading the view in, animate the effect property from nil to the blur effect. You can fade in the rest of your view hierarchy if needed. This will neatly animate the blur radius similar to how it looks when you pull the home screen icons down.

这篇关于iOS 10中的UIVisualEffectView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆