iOS 8.0 毛玻璃效果UIVisualEffect

 随着iOS8.0和OS X 10.0的发布,大量的毛玻璃效果随处可见.

   以前我们实现毛玻璃效果,更多是通过CGImage来实现.现在,XCode6中自带了实现这一效果的API.API如下:

[objc]  view plain copy
  1. typedef NS_ENUM(NSInteger, UIBlurEffectStyle) {  
  2.     UIBlurEffectStyleExtraLight,  
  3.     UIBlurEffectStyleLight,  
  4.     UIBlurEffectStyleDark  
  5. } NS_ENUM_AVAILABLE_IOS(8_0);  
  6.   
  7. NS_CLASS_AVAILABLE_IOS(8_0@interface UIVisualEffect : NSObject <NSCopying, NSSecureCoding> @end  
  8.   
  9. /* 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. */  
  10. NS_CLASS_AVAILABLE_IOS(8_0@interface UIBlurEffect : UIVisualEffect  
  11. + (UIBlurEffect *)effectWithStyle:(UIBlurEffectStyle)style;  
  12. @end  
  13.   
  14. /* 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. 
  15.  */  
  16. NS_CLASS_AVAILABLE_IOS(8_0@interface UIVibrancyEffect : UIVisualEffect  
  17. + (UIVibrancyEffect *)effectForBlurEffect:(UIBlurEffect *)blurEffect;  
  18. @end  
  19.   
  20. NS_CLASS_AVAILABLE_IOS(8_0@interface UIVisualEffectView : UIView <NSSecureCoding>  
  21. @property (nonatomicretainreadonlyUIView *contentView; // Do not add subviews directly to UIVisualEffectView, use this view instead.  
  22. @property (nonatomiccopyreadonlyUIVisualEffect *effect;  
  23. - (instancetype)initWithEffect:(UIVisualEffect *)effect NS_DESIGNATED_INITIALIZER;  
  24. @end  

      @测试代码:

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. // 图片  
  2. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10100300400)];  
  3. [imageView setImage:[UIImage imageNamed:@"IMG_0015.JPG"]];  
  4. [self.view addSubview:imageView];  
  5.   
  6. // blur效果  
  7. self.visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];  
  8. _visualEfView.frame = CGRectMake(00300400);  
  9. _visualEfView.alpha = 1.0;  
  10. [imageView addSubview:_visualEfView];  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值