【发布时间】:2014-08-15 12:44:27
【问题描述】:
我有一个UIViewController,它以模态方式呈现另一个UIViewController。我希望模态视图控制器具有 iOS 7 引入的模糊/透明度。我尝试使用新的UIVisualEffect,但它似乎只适用于UIViews,而不适用于UIViewControllers?
这是我编写的代码,我作为子视图添加的所有视图都是我想要在用户界面上方模糊视图下方的视图。
在呈现视图控制器中,我在应用模糊之前截取了传递给模态视图控制器的屏幕截图。
在展示视图控制器中:
- (UIImage *)viewImage {
CGSize size = CGSizeMake(self.view.frame.size.width,self.view.frame.size.height);
UIGraphicsBeginImageContext(size);
[self.view drawViewHierarchyInRect:(CGRect){CGPointZero, self.view.frame.size.width, self.view.frame.size.height} afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
在模态视图控制器中:
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:[[UIImageView alloc] initWithImage:self.backgroundImage]];
//self.backgroundImage is the image that the method above returns, it's a screenshot of the presenting view controller.
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
[blurEffectView setFrame:self.view.bounds];
[self.view addSubview:blurEffectView];
[self.view bringSubviewToFront:self.cancelButton];
[self.view bringSubviewToFront:self.titleLabel];
[self.view bringSubviewToFront:self.tableView];
}
【问题讨论】:
-
stackoverflow.com/questions/17036655ios-7-style-blur-view
标签: ios iphone objective-c user-interface