【发布时间】:2014-12-18 14:06:23
【问题描述】:
我在模态 uiviewcontroller 的 viewWillAppear 中有以下代码。
我在这个例子中包含了 UIImage+ImageEffects.h 来做背景图像的模糊处理。
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:NO];
// grab an image of our parent view
UIView *parentView = self.presentingViewController.view;
UIImage *parentViewImage = [self takeSnapshotOfView:parentView];
UIImage *blurredImage = nil;
//BLUR THE IMAGE
blurredImage = [self blurWithImageEffects:parentViewImage];
// insert an image view with a picture of the parent view at the back of our view's subview stack...
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.image = blurredImage;
[self.view insertSubview:imageView atIndex:0];
}
[编辑] 添加模糊方法
- (UIImage *)takeSnapshotOfView:(UIView *)view
{
CGFloat reductionFactor = 1.5;
UIGraphicsBeginImageContext(CGSizeMake(view.frame.size.width/reductionFactor, view.frame.size.height/reductionFactor));
[view drawViewHierarchyInRect:CGRectMake(0, 0, view.frame.size.width/reductionFactor, view.frame.size.height/reductionFactor) afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (UIImage *)blurWithImageEffects:(UIImage *)image
{
return [image applyBlurWithRadius:10 tintColor:[UIColor colorWithWhite:1 alpha:0.2] saturationDeltaFactor:1.5 maskImage:nil];
}
代码工作正常,背景显示模糊,但在装有 iOS 8 的 iPad 3 上确实明显慢。当点击显示此视图控制器的按钮时,在视图控制器从底部向上滑动之前会有一个暂停。如果我移除模糊,视图控制器会更快地向上滑动。
我尝试将代码放入 viewDidAppear 中,但随后会出现明显的白色背景,持续几秒钟后出现模糊。但是当在 viewDidAppear 中时,viewcontroller 会立即向上滑动。
如果我减小 applyWithBlurRadius 值,这似乎不会减少应用模糊所需的时间。
有什么办法可以让它跑得更快?
【问题讨论】:
-
你可以试试 iOS 8 设备的 UIVisualEffect。
-
@skorulls 我会,但我似乎没有使用 UIVisualEffects 进行相同级别的控制,因为只有 3 级模糊可用,我似乎无法更改。我已经用图像模糊方法更新了我的问题。
标签: objective-c ipad uiimage ios8 uiblureffect