iOS如何创建模糊自身内容的UIView
我有一个iOS如何创建模糊自身内容的UIView,ios,objective-c,uiview,blur,Ios,Objective C,Uiview,Blur,我有一个ui视图,它部分覆盖了一些内容,我想应用一种与iOS通知中心完全相同的模糊效果 我不是想在UIImage上应用模糊,而是在UIView上应用模糊,并在其下添加其他内容(UIView,UIButton,ecc) 想法? 谢谢 从另一个答案来看,无论我如何在项目中使用工具栏,工作都非常完美,我使用的是alpha=0.98,首先将UIView更改为UIImage。 您可以将以下内容用作UIView的类别 @implementation UIView (ConvertToUIImage) -
ui视图
,它部分覆盖了一些内容,我想应用一种与iOS通知中心完全相同的模糊效果
我不是想在UIImage
上应用模糊,而是在UIView
上应用模糊,并在其下添加其他内容(UIView
,UIButton
,ecc)
想法?
谢谢
从另一个答案来看,无论我如何在项目中使用工具栏,工作都非常完美,我使用的是alpha=0.98,首先将UIView更改为UIImage。 您可以将以下内容用作UIView的类别
@implementation UIView (ConvertToUIImage)
- (UIImage *)asImage {
NSAssert(self, @"Do not use this method on nil instance of UIView.");
if (!self) return 0;
UIGraphicsBeginImageContextWithOptions(self.frame.size, YES, 0);
[self drawViewHierarchyInRect:self.frame afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSAssert(image, @"Image must not be nil at this point.");
return image;
}
@end
接下来需要模糊UIImage,这里有一个相关的问题
最后,使用UIImage作为背景。这个类应该提供你想要的:不会提供模糊效果。我有一个
UIView
,我需要UIView
,正如我在问题中所写的,我不是在寻找一种方法来对UIImage
应用模糊查看你发布的屏幕截图。主屏幕可视为viewA,通知中心可视为viewB。其思想是在显示viewB之前创建viewA的UIImage表示。然后模糊UIImage,最后将其添加为viewB的背景。现在,如果您呈现viewB,它将在viewA的顶部显示为透明,其中viewA是模糊的-就像在发布的屏幕截图中一样。在马特·纽伯格(Matt Neuburg)的《编程iOS 7》(Programming iOS 7)一书中,还有其他类似的技巧。我误解你的要求了吗?
@implementation UIView (ConvertToUIImage)
- (UIImage *)asImage {
NSAssert(self, @"Do not use this method on nil instance of UIView.");
if (!self) return 0;
UIGraphicsBeginImageContextWithOptions(self.frame.size, YES, 0);
[self drawViewHierarchyInRect:self.frame afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSAssert(image, @"Image must not be nil at this point.");
return image;
}
@end