陈斌彬的技术博客

Stay foolish,stay hungry

iOS 开源项目-FXBlurView

Purpose

FXBlurView is a UIView subclass that replicates the iOS 7 realtime background blur effect, but works on iOS 5 and above. It is designed to be as fast and as simple to use as possible. FXBlurView offers two modes of operation: static, where the view is rendered only once when it is added to a superview (though it can be updated by calling setNeedsDisplay or updateAsynchronously:completion:) or dynamic, where it will automatically redraw itself on a background thread as often as possible.

FXBlurView 是一个 UIView 的子类,复制了 iOS7 的实时背景模糊效果,但是可以运行在 iOS5 以上的版本。它的设计简单易用。FXBlurView 提供两种模式:静态模糊和动态模糊。

FXBlurView methods

1
+(void)setBlurEnabled:(BOOL)blurEnabled;

This method can be used to globally enable/disable the blur effect on all FXBlurView instances. This is useful for testing, or if you wish to disable blurring on iPhone 4 and below (for consistency with iOS7 blur view behavior). By default blurring is enabled.

这个方法用来设置全局 使能/不使能 模糊效果在 FXBlurView 的实例上。默认情况下模糊效果是启动。

1
2
+(void)setUpdatesEnabled;
+(void)setUpdatesDisabled;

These methods can be used to enable and disable updates for all dynamic FXBlurView instances with a single command. Useful for disabling updates immediately before performing an animation so that the FXBlurView updates don’t cause the animation to stutter. Calls can be nested, but ensure that the enabled/disabled calls are balanced, or the updates will be left permanently enabled or disabled.

这两个方法用来设置所以的动态 FXBlurView 是否进行更新,通过一条指令执行。在展示动画之前立即对没有用的更新进行更新,使 FXBlurView 更新不会产生动画断断续续的效果。调用可以嵌套,但确保 启用/禁用 调用平衡,否则更新会留下永久 启用/禁用。

1
-(void)updateAsynchronously:(BOOL)async completion:(void (^)())completion;

This method can be used to trigger an update of the blur effect (useful when dynamic = NO). The async argument controls whether the blur will be redrawn on the main thread or in the background. The completion argument is an optional callback block that will be called when the blur is completed.

这个方法可以用于触发更新模糊效果。(在属性 "dynamic = NO"情况下有用)。异步参数控制是否模糊将要在主线程上或在后台进行重绘。完成参数是一个可供选择的回调块,将在模糊完成的时候进行调用。

1
-(void)setNeedsDisplay;

Inherited from UIView, this method can be used to trigger a (synchronous) update of the view. Calling this method is more-or-less equivalent to calling [view updateAsynchronously:NO completion:NULL].

继承 UIView,这个方法用于触发一个(同步)更新视图。调用这个方法或多或少等同于调用[view updateAsynchronously:NO completion:NULL].

FXBlurView properties

1
@property (nonatomic, getter = isBlurEnabled) BOOL blurEnabled;

This property toggles blurring on and off for an individual FXBlurView instance. Blurring is enabled by default. Note that if you disable blurring using the +setBlurEnabled method then that will override this setting.

这个属性用来切换 FXBlurView 单独实例模糊启动还是关闭。默认情况下模糊是使能的。请注意,如果您禁用模糊方法 setBlurEnabled,那么它将覆盖此设置。

1
 @property (nonatomic, getter = isDynamic) BOOL dynamic;

This property controls whether the FXBlurView updates dynamically, or only once when the view is added to its superview. Defaults to YES. Note that if dynamic is set to NO, you can still force the view to update by calling setNeedsDisplay or updateAsynchronously:completion:. Dynamic blurring is extremely cpu-intensive, so you should always disable dynamic views immediately prior to performing an animation to avoid stuttering. However, if you have multiple FXBlurViews on screen then it is simpler to disable updates using the setUpdatesDisabledmethod rather than setting the dynamic property to NO.

这个属性控制 FXBlurView 是否动态更新,还是只有在视图加入到它的父视图中。默认情况下是 YES ,请注意,如果你设置 dynamic 属性为 NO,你可以强制视图更新通过调用 setNeedsDisplay或者updateAsynchronously:completion:。动态模糊非常消耗 CPU 内存,所以您应该禁用立即执行的动态视图避免出现断断续续的动画。然而,如果您在屏幕上有多个 FXBlurViews ,通过设置方法 setUpdatedsDisabled来禁止更新比用设置动态属性为 NO 更为简单。

1
@property (nonatomic, assign) NSUInteger iterations;

The number of blur iterations. More iterations improves the quality but reduces the performance. Defaults to 2 iterations.

模糊迭代的次数。更多的迭代提高质量,但会降低性能。默认值为 2 的迭代。

1
@property (nonatomic, assign) NSTimeInterval updateInterval;

This controls the interval (in seconds) between successive updates when the FXBlurView is operating in dynamic mode. This defaults to zero, which means that the FXBlurView will update as fast as possible. This yields the best frame rate, but is also extremely CPU intensive and may cause the rest of your app’s performance to degrade, especially on older devices. To alleviate this, try increasing the updateInterval value.

此属性控制 FXBlurView 在动态模式下,距离成功更新的时间间隔(以秒计)。默认值为 0 ,这表示 FXBlurView 更新越快越好。 这将生成最佳的帧速率,但是也是非常消耗 CPU内存,导致你的其他 apps 无法无法加载,特别是旧设备。为了减缓这些情况,尝试增加updateInterval 的值。

1
@property (nonatomic, assign) CGFloat blurRadius;

This property controls the radius of the blur effect (in points). Defaults to a 40 point radius, which is similar to the iOS 7 blur effect.

此属性控制模糊效果的半径 (以像素点计)。默认是半径为40个像素点,这个值与 iOS7 模糊效果相似。

1
@property (nonatomic, strong) UIColor *tintColor;

This in an optional tint color to be applied to the FXBlurView. The RGB components of the color will be blended with the blurred image, resulting in a gentle tint. To vary the intensity of the tint effect, use brighter or darker colors. The alpha component of the tintColor is ignored. If you do not wish to apply a tint, set this value to nil or [UIColor clearColor]. Note that if you are using Xcode 5 or above, FXBlurViews created in Interface Builder will have a blue tint by default.

这是应用在 FXBlurView 可选的色调选择。颜色的 RGB 分量将会掺入到模糊图像上,导致产生一个柔和的色调。为了验证色调效果,若要改变色调效果的强度,使用更亮或更暗的颜色。颜色的透明参数是被忽略的。如果您不想应用色调,设置[UIColor clearColor]。请注意,如果您现在使用 Xcode5及以上,FXBlurViews 产生一个接口生成器将默认有一个一个蓝色的色调。

1
@property (nonatomic, weak) UIView *underlyingView;

This property specifies the view that the FXBlurView will sample to create the blur effect. If set to nil (the default), this will be the superview of the blur view itself, but you can override this if you need to.

此属性表明该视图是 FXBlurView 产生模糊效果的子视图。如果设置为 nil(默认),则该视图的父视图是模糊视图本身,但是如果您有需要您可以进行覆盖它。

总结

今天通过学习 FXBlurView ,提高对英语文档的理解和翻译能力,增加了自己的学习兴趣,也懂得了如何去使用 FXBlurView 的模糊效果特效。在实际中提升自己的能力,年轻,就是资本!Oh Yeah!

参考