iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIVisualEffectView Class Reference

Options
Deployment Target:

On This Page
Language:

UIVisualEffectView

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 8.0 and later.

A UIVisualEffectView object gives you an easy way implement some complex visual effects. Depending on the desired effect, the effect may affect content layered behind the view or content added to the visual effect view’s contentView.

Apply a visual effect view to an existing view and then apply a UIBlurEffect or UIVibrancyEffect object to apply a blur or vibrancy effect to the existing view. After you add the visual effect view to the view hierarchy, add any subviews to the contentView property of the visual effect view. Do not add subviews directly to the visual effect view itself.

Setting the Correct Alpha Value

When using the UIVisualEffectView class, avoid alpha values that are less than 1. Creating views that are partially transparent causes the system to combine the view and all the associated subviews during an offscreen render pass. UIVisualEffectView objects need to be combined as part of the content they are layered on top of in order to look correct. Setting the alpha to less than 1 on the visual effect view or any of its superviews causes many effects to look incorrect or not show up at all.

Using Masks with a UIVisualEffectView

Masks directly applied to a UIVisualEffectView are forwarded to the internal views that provide the visual effect, including the contentView itself. You can also apply masks directly to the contentView. Applying a mask to a superview of a UIVisualEffectView object causes the effect to fail, and an exception is thrown.

Any mask provided to UIVisualEffectView is not the view that actually performs the mask. UIKit makes a copy of the view and applies it to each subview. To reflect a size change to the mask, you must apply the change to the original mask and reset it on the effect view.

Capturing a Snapshot of a UIVisualEffectView

Many effects require support from the window that hosts the UIVisualEffectView. Attempting to take a snapshot of only the UIVisualEffectView will result in a snapshot that does not contain the effect. To take a snapshot of a view hierarchy that contains a UIVisualEffectView, you must take a snapshot of the entire UIWindow or UIScreen that contains it.

  • A UIView object that can have a visual effect view added to it. (read-only)

    Declaration

    Swift

    var contentView: UIView { get }

    Objective-C

    @property(nonatomic, retain, readonly) UIView *contentView

    Discussion

    Add subviews to the contentView and not to UIVisualEffectView directly.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • effect effect Property

    The visual effect provided by the view. (read-only)

    Declaration

    Swift

    @NSCopying var effect: UIVisualEffect { get }

    Objective-C

    @property(nonatomic, copy, readonly) UIVisualEffect *effect

    Discussion

    The effect is either a UIBlurEffect or a UIVibrancyEffect.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • init(effect:) - initWithEffect: Designated Initializer

    Creates a new visual effect view with the designated visual effect.

    Declaration

    Swift

    init(effect effect: UIVisualEffect)

    Objective-C

    - (instancetype)initWithEffect:(UIVisualEffect *)effect

    Parameters

    effect

    The UIVisualEffect you provide for the view. This can be a UIBlurEffect or a UIVibrancyEffect.

    Return Value

    The new view containing the designated visual effect.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.