IOS 8.0 frosted glass effect UIVisualEffect

Source: Internet
Author: User

IOS 8.0 frosted glass effect UIVisualEffect

With the release of iOS8.0 and OS X 10.0, a large number of glass wool effects can be seen everywhere.

Previously, we implemented the frosted glass effect through CGImage. Now, XCode6 has its own API to achieve this effect. The API is as follows:

typedef NS_ENUM(NSInteger, UIBlurEffectStyle) {    UIBlurEffectStyleExtraLight,    UIBlurEffectStyleLight,    UIBlurEffectStyleDark} NS_ENUM_AVAILABLE_IOS(8_0);NS_CLASS_AVAILABLE_IOS(8_0) @interface UIVisualEffect : NSObject 
 
   @end/* UIBlurEffect will provide a blur that appears to have been applied to the content layered behind the UIVisualEffectView. Views added to the contentView of a blur visual effect are not blurred themselves. */NS_CLASS_AVAILABLE_IOS(8_0) @interface UIBlurEffect : UIVisualEffect+ (UIBlurEffect *)effectWithStyle:(UIBlurEffectStyle)style;@end/* UIVibrancyEffect amplifies and adjusts the color of content layered behind the view, allowing content placed inside the contentView to become more vivid. It is intended to be placed over, or as a subview of, a UIVisualEffectView that has been configured with a UIBlurEffect. This effect only affects content added to the contentView. Because the vibrancy effect is color dependent, subviews added to the contentView need to be tintColorDidChange aware and must be prepared to update themselves accordingly. UIImageView will need its image to have a rendering mode of UIImageRenderingModeAlwaysTemplate to receive the proper effect. */NS_CLASS_AVAILABLE_IOS(8_0) @interface UIVibrancyEffect : UIVisualEffect+ (UIVibrancyEffect *)effectForBlurEffect:(UIBlurEffect *)blurEffect;@endNS_CLASS_AVAILABLE_IOS(8_0) @interface UIVisualEffectView : UIView 
  
   @property (nonatomic, retain, readonly) UIView *contentView; // Do not add subviews directly to UIVisualEffectView, use this view instead.@property (nonatomic, copy, readonly) UIVisualEffect *effect;- (instancetype)initWithEffect:(UIVisualEffect *)effect NS_DESIGNATED_INITIALIZER;@end
  
 

@ Test code:

// Image UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (10,100,300,400)]; [imageView setImage: [UIImage imageNamed: @ "IMG_0015.JPG"]; [self. view addSubview: imageView]; // blur effect self. visualEfView = [[UIVisualEffectView alloc] initWithEffect: [UIBlurEffect effectWithStyle: UIBlurEffectStyleLight]; _ visualEfView. frame = CGRectMake (0, 0,300,400); _ visualEfView. alpha = 1.0; [imageView addSubview: _ visualEfView];
@ Demo running effect:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.