如何获得类似于Apple Maps状态栏的模糊效果? [英] How to get blur effect similar to Apple maps status bar?

查看:65
本文介绍了如何获得类似于Apple Maps状态栏的模糊效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于地图的iOS 11应用程序,并希望使状态栏变得完全模糊,就像它在Apple地图中一样.

这是它在地图"应用中的外观:

当前,我正在使用UIVisualEffectView复制此效果.这是我的代码:

 让blurEffect = UIBlurEffect(style:.regular)blurStatusBar = UIVisualEffectView(effect:blurEffect)bluredStatusBar?.translatesAutoresizingMaskIntoConstraints = falseview.addSubview(blurredStatusBar!) 

但是,无论我使用什么UIBlurEffect,我都无法复制类似于Maps应用程序的效果.这就是它寻找不同效果的方式:

.常规

.突出

.light

.extraLight

我只想模糊状态栏,而不添加任何饱和度,鲜艳度或任何白色色调.

有一个实例属性-

我尝试了几种不同的方法,例如,但是没有用.

解决方案

我找到了上述问题的解决方案.我使用 VisualEffectView 来达到效果.它使您可以自定义诸如colortint,blurRadius,VisualEffectView的模糊比例的属性.但是,应谨慎使用.它利用私有的UIKit API来发挥作用.将此代码提交到App Store会增加被拒绝的风险!

I'm working on a map based iOS 11 application and want to make the status bar blurred exactly like it appears in the Apple maps.

This is how it looks on the Maps app:

Currently, I'm using UIVisualEffectView to replicate this effect. Here's my code:

let blurEffect = UIBlurEffect(style: .regular)
blurredStatusBar = UIVisualEffectView(effect: blurEffect)
blurredStatusBar?.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(blurredStatusBar!)

However, whatever UIBlurEffect I use, I'm not able to replicate the effect like Maps app. Here's how it looks for different effects:

.regular

.prominent

.light

.extraLight

I just want to the blur the status bar, without adding any saturation, vibrancy or any white color tint.

There is an instance property - backgroundFilters, which, possibly could have helped me but unfortunately it is not available for layers on iOS.

One possible solution suggested here was to capture the UIView content inside an image, then blurring and showing it. However, this is not a feasible solution in my case because I've got a map underneath the status bar which can be panned. It does not makes sense to continuously capture the underneath map as an image and blur it while the map is being panned.

I tried using ILTranslucentView, which is a little subclass of UIView that provide native iOS 7+ blur (translucent) effect. This is how it appeared:

I tried a couple of different approaches like this, but to no use.

解决方案

I found the solution for the above problem. I used VisualEffectView to achieve the effect. It lets you to customise the properties like colortint, blurRadius, scale of blur of your VisualEffectView. However, this should be used with caution. It utilizes a private UIKit API to do its magic; submitting this code to the App Store adds the risk of being rejected!

这篇关于如何获得类似于Apple Maps状态栏的模糊效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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