相关疑难解决方法(0)

如何将UIBlurEffect与模态视图控制器一起使用?

我有一个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;
}
Run Code Online (Sandbox Code Playgroud)

在模态视图控制器中:

- (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 …
Run Code Online (Sandbox Code Playgroud)

iphone user-interface objective-c ios

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

user-interface ×1