我有一个模态视图,我想要显示计算结果。为了让所有的iOS7看起来,我想要一个带有模糊背景的弹出视图的有色背景。UIImage + ImageEffects无法在设备上工作
我设法使用苹果公司的“UIImage + ImageEffects.h/m”文件工作。
这是模态视图的viewDidLoad中:
- (void)viewDidLoad {
[super viewDidLoad];
/* How it works
self.image is a screenshot of the VC presenting the modal view
1- we set the background as the screenshot of the previous viewControler
2- we hide the popup view
3- we set the background of the popup as a blured snapshot of its container view (self.view)
4- we unhide the popup view and set its radius
5- we create a tinted version of the background image (what we got from the previous view controller
6- we set the background of self.view to the tinted version
*/
// *** 1 ***
self.view.backgroundColor=[UIColor colorWithPatternImage:self.image];
// *** 2 ***
self.containerView.hidden=YES;
// *** 3 ***
UIImage *pepe=[self bluredImageFromView:self.containerView withBackground:self.view withBackgroundTintColor:[UIColor colorWithWhite:1 alpha:0.75]];
self.containerView.backgroundColor=[UIColor colorWithPatternImage:pepe];
// *** 4 ***
self.containerView.hidden=NO;
self.containerView.layer.cornerRadius=4.5f;
// *** 5 ***
UIImage *tintedBackground =[self.image applyBlurWithRadius:0
tintColor:[UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:0.35]
saturationDeltaFactor:1.8
maskImage:nil];
// *** 6 ***
self.view.backgroundColor=[UIColor colorWithPatternImage:tintedBackground];
}
它工作得很好的模拟器但是当我试图onmy iPhone(4S),提出了模态视图的时候,我有一个黑色的屏幕。没有错误,没有抱怨从控制台,没有任何。
有什么想法?
编辑
我添加代码:
if (!self.image) NSLog (@"self.image is empty");
在viewDidLoad中
之初看来,在模拟器上self.image不为零,而在设备上它是。我尝试从父VC上的prepareForSegue实例化self.image,但不起作用。
非常感谢!我实际上是修改了Ray Wenderlicht的教程中的一段剪辑代码,这正是你指出的那个线程。我使用您提供的这些代码调整了我的方法,现在它像魅力一样工作。我不知道该怎么感谢你才足够! – Marcal
不客气。我很想知道'applyBlurWithRadius:tintColor:saturationDeltaFactor:maskImage:'是否适用于iPhone 4. –
我只能告诉你,用我的4s可以完美无瑕。我会在提交应用程序之前几天在我的iPad 3上尝试它。 – Marcal