iOS 7风格模糊视图

有没有人知道任何将复制iOS7风格模糊视图的控件。

我假设可能会有某种UIView子类将复制的行为。

我正在谈论这些types的视图模糊背景非常厚,使他们从背景视图拉动效果。

在这里输入图像说明

您可能可以修改像张斌的RWBlurPopover这样的东西。 该组件使用我的GPUImage将高斯模糊应用于其下的组件,但是您可以像使用CIGaussianBlur一样轻松地使用它。 尽pipeGPUImage可能会更快 。

然而,这个组件依赖于你能够捕捉到你正在呈现的视图背后的视图,并且可能在这个内容背后的视图上有麻烦。 通过Core Graphics来浏览栅格化背景视图的需求会减慢速度,所以我们可能没有足够的直接访问权限,无法以高性能的方式对animation视图进行覆盖。

作为上面的更新,我最近重新修改了GPUImage中的模糊来支持可变半径,从而允许在iOS 7的控制中心视图中完全复制模糊大小。 从那以后,我创build了GPUImageiOS7BlurFilter类,它封装了Apple在这里使用的正确的模糊大小和颜色校正。 这是GPUImage模糊(右侧)与内置模糊(左侧)的比较:

苹果的模糊GPUImage模糊

我使用4倍下采样/上采样来减less高斯模糊必须操作的像素数量,因此iPhone 4S可以使用此操作在大约30 ms内模糊整个屏幕。

您仍然面临着如何以高性能的方式将内容从视图背后拖入到模糊中的挑战。

我正在使用FXBlurView ,它在iOS5 +上效果很好

https://github.com/nicklockwood/FXBlurView

的CocoaPods:

 -> FXBlurView (1.3.1) UIView subclass that replicates the iOS 7 realtime background blur effect, but works on iOS 5 and above. pod 'FXBlurView', '~> 1.3.1' - Homepage: http://github.com/nicklockwood/FXBlurView - Source: https://github.com/nicklockwood/FXBlurView.git - Versions: 1.3.1, 1.3, 1.2, 1.1, 1.0 [master repo] 

我通过使用:

 FXBlurView *blurView = [[FXBlurView alloc] initWithFrame:CGRectMake(50, 50, 150, 150)]; [self.blurView setDynamic:YES]; [self.view addSubview:self.blurView]; 

警告:有人在评论中指出,苹果拒绝使用这种技术的应用程序。 那不会发生在我身上,只是为了您的考虑。

这可能会让你感到惊讶,但是你可以使用一个已经包含标准效果(仅适用于iOS 7+) 的UIToolbar 。 在你查看控制器的viewDidLoad:

 self.view.opaque = NO; self.view.backgroundColor = [UIColor clearColor]; // Be sure in fact that EVERY background in your view's hierarchy is totally or at least partially transparent for a kind effect! UIToolbar *fakeToolbar = [[UIToolbar alloc] initWithFrame:self.view.bounds]; fakeToolbar.autoresizingMask = self.view.autoresizingMask; // fakeToolbar.barTintColor = [UIColor white]; // Customize base color to a non-standard one if you wish [self.view insertSubview:fakeToolbar atIndex:0]; // Place it below everything 

自iOS8以来,您可以使用UIBlurEffect 。

在UIBlurEffect和UIVibrancyEffect的iOS8Sampler上有一个很好的例子 。

获得Blured Overlay的最佳新方法是使用新的iOS 8functionUIVisualEffectView。

 UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; UIVisualEffectView *bluredView = [[UIVisualEffectView alloc] initWithEffect:effect]; bluredView.frame = self.view.bounds; [self.view addSubview:bluredView]; 

UIBlurEffect支持三种风格。 黑暗,光线和ExtraLight。

你可以用UIToolBar创build一个UIView的子类,并在独立的视图控制器中实例化它。 这种方法演示了一个半透明的UIToolBar(由UIView分类),提供实时反馈(在这种情况下为AVCaptureSession)。

YourUIView.h

 #import <UIKit/UIKit.h> @interface YourUIView : UIView @property (nonatomic, strong) UIColor *blurTintColor; @property (nonatomic, strong) UIToolbar *toolbar; @end 

YourUIView.m

 #import "YourUIView.h" @implementation YourUIView - (instancetype)init { self = [super init]; if (self) { [self setup]; } return self; } - (void)setup { // If we don't clip to bounds the toolbar draws a thin shadow on top [self setClipsToBounds:YES]; if (![self toolbar]) { [self setToolbar:[[UIToolbar alloc] initWithFrame:[self bounds]]]; [self.toolbar setTranslatesAutoresizingMaskIntoConstraints:NO]; [self insertSubview:[self toolbar] atIndex:0]; [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_toolbar]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_toolbar)]]; [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_toolbar]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(_toolbar)]]; } } - (void) setBlurTintColor:(UIColor *)blurTintColor { [self.toolbar setBarTintColor:blurTintColor]; } @end 

一旦上面的UIView已经定制,继续创build一个ViewController的子类的类。 下面我创build了一个使用AVCapture会话的类。 您必须使用AVCaptureSession来覆盖苹果的内置摄像头configuration。 因此,您可以覆盖来自YourUIView类的trancylucent UIToolBar

YourViewController.h

 #import <UIKit/UIKit.h> @interface YourViewController : UIViewController @property (strong, nonatomic) UIView *frameForCapture; @end 

YourViewController.m

 #import "YourViewController.h" #import <AVFoundation/AVFoundation.h> #import "TestView.h" @interface YourViewController () @property (strong, nonatomic) UIButton *displayToolBar; @end @implementation YourViewController AVCaptureStillImageOutput *stillImageOutput; AVCaptureSession *session; - (void) viewWillAppear:(BOOL)animated { session = [[AVCaptureSession alloc] init]; [session setSessionPreset:AVCaptureSessionPresetPhoto]; AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; NSError *error; AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error]; if ([session canAddInput:deviceInput]) { [session addInput:deviceInput]; } AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; CALayer *rootLayer = [[self view] layer]; [rootLayer setMasksToBounds:YES]; CGRect frame = [[UIScreen mainScreen] bounds]; self.frameForCapture.frame = frame; [previewLayer setFrame:frame]; [rootLayer insertSublayer:previewLayer atIndex:0]; stillImageOutput = [[AVCaptureStillImageOutput alloc] init]; NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil]; [stillImageOutput setOutputSettings:outputSettings]; [session addOutput:stillImageOutput]; [session startRunning]; [self.navigationController setNavigationBarHidden:YES animated:animated]; [super viewWillAppear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; /* Open button */ UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 350, self.view.bounds.size.width, 50)]; [button addTarget:self action:@selector(showYourUIView:) forControlEvents:UIControlEventTouchUpInside]; [button setTitle:@"Open" forState:UIControlStateNormal]; [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; button.backgroundColor = [UIColor greenColor]; [self.view addSubview:button]; UIButton *anotherButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, 50)]; [anotherButton addTarget:self action:@selector(showYourUIView:) forControlEvents:UIControlEventTouchUpInside]; [anotherButton setTitle:@"Open" forState:UIControlStateNormal]; [anotherButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; anotherButton.backgroundColor = [UIColor redColor]; [self.view addSubview:anotherButton]; } - (void) showYourUIView:(id) sender { TestView *blurView = [TestView new]; [blurView setFrame:self.view.bounds]; [self.view addSubview:blurView]; } @end