iOS 8.0 毛半透明效果UIVisualEffect

來源:互聯網
上載者:User

標籤:毛玻璃   uivisualeffect   

   隨著iOS8.0和OS X 10.0的發布,大量的毛半透明效果隨處可見.

   以前我們實現毛半透明效果,更多是通過CGImage來實現.現在,XCode6中內建了實現這一效果的API.API如下:

typedef NS_ENUM(NSInteger, UIBlurEffectStyle) {    UIBlurEffectStyleExtraLight,    UIBlurEffectStyleLight,    UIBlurEffectStyleDark} NS_ENUM_AVAILABLE_IOS(8_0);NS_CLASS_AVAILABLE_IOS(8_0) @interface UIVisualEffect : NSObject <NSCopying, NSSecureCoding> @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 <NSSecureCoding>@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

      @測試代碼:

    // 圖片    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 400)];    [imageView setImage:[UIImage imageNamed:@"IMG_0015.JPG"]];    [self.view addSubview:imageView];        // blur效果    self.visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];    _visualEfView.frame = CGRectMake(0, 0, 300, 400);    _visualEfView.alpha = 1.0;    [imageView addSubview:_visualEfView];
     @Demo運行效果:


iOS 8.0 毛半透明效果UIVisualEffect

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.