简体   繁体   English

自定义UIViewController过渡与模糊

[英]Custom UIViewController Transition with Blur

I'm trying to achieve a transition of my UIViewController where is very simply zooms out slightly and blurs so that it sits faded in the background. 我正在尝试实现UIViewController的过渡,其中非常简单地将其稍微缩小并模糊,使其在背景中褪色。 I have looked at a lot of solutions but I can't find anything surrounding blurring specifically. 我已经看过很多解决方案,但是我找不到关于模糊的任何东西。

Currently I am just playing with taking a screen of the parent view controller and animating that in the child. 目前,我只是在玩一个父视图控制器的屏幕,并在孩子中对其进行动画处理。

Apps such as Tweetbot 3 and Pinterest are notable ones which do this, see a screenshot here, exactly what I mean: 诸如Tweetbot 3和Pinterest之类的应用程序就是值得注意的应用程序,请参见此处的屏幕截图,确切地说是我的意思:

在此处输入图片说明

I'm struggling with it smoothly blur out. 我正在努力使其平滑脱颖而出。 Any suggestions on how to achieve this effect? 关于如何达到这种效果有什么建议吗?

iOS 7 Solution: iOS 7解决方案:

You can display it in UIImageView and place on top of other UIViews. 您可以在UIImageView中显示它,并将其放置在其他UIView的顶部。 In the past, I used renderInContext in CALayer. 过去,我在CALayer中使用renderInContext。

UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view drawViewHierarchyInRect:self.view.bounds];
UIImage *blurImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Once you capture UIView screenshot, apply blur effect. 捕获UIView屏幕截图后,请应用模糊效果。 Unfortunately, there is no public API available yet for blur effect, but Apple has a sample implementation in sample code. 不幸的是,目前尚没有用于模糊效果的公共API,但是Apple在示例代码中提供了一个示例实现。 It's a Category for UIImage. 这是UIImage的类别。 Please search a sample code in Xcode documentations. 请在Xcode文档中搜索示例代码。 After adding UIImage category files to your project, you can blur an image like this: 将UIImage类别文件添加到您的项目后,您可以使图像模糊,如下所示:

blurImg = [blurImg applyDarkEffect];

Prior to iOS 7 Solution: https://github.com/tomsoft1/StackBluriOS 在iOS 7解决方案之前: https : //github.com/tomsoft1/StackBluriOS

UIImage *blurImg = [originalImg stackBlur:radius];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM