是否有人知道将复制iOS7样式模糊视图的任何控件。
我假设可以存在某种UIView子类来复制行为。
我说的是这些类型的视图,它们会使背景变得非常模糊,以至于它们从背景视图中产生拉动效果。


是否有人知道将复制iOS7样式模糊视图的任何控件。
我假设可以存在某种UIView子类来复制行为。
我说的是这些类型的视图,它们会使背景变得非常模糊,以至于它们从背景视图中产生拉动效果。


Answers:
您可以修改Bin Zhang的RWBlurPopover之类的方法来执行此操作。该组件使用我的GPUImage将高斯模糊应用于其下面的组件,但是您也可以轻松地使用CIGaussianBlur对其进行处理。不过GPUImage可能快了一点。
但是,该组件依赖于您能够捕获正在呈现的视图后面的视图,并且可能无法为该内容后面的动画设置视图。需要通过Core Graphics来光栅化背景视图会减慢速度,因此我们可能没有足够的直接访问权限,无法以高性能的方式在动画视图上进行叠加。
作为对上述内容的更新,我最近重新处理了GPUImage中的模糊以支持可变半径,从而可以在iOS 7的控制中心视图中完全复制模糊大小。由此,我创建了GPUImageiOS7BlurFilter类,该类封装了Apple似乎在此处使用的适当的模糊大小和颜色校正。这就是GPUImage的模糊(右侧)与内置模糊(左侧)的比较方式:
 
 
我使用4倍下采样/上采样来减少需要进行高斯模糊处理的像素数,因此iPhone 4S使用此操作可以在大约30毫秒内使整个屏幕模糊。
您仍然面临着如何以高效的方式将内容从该视图后面的模糊中拉出的挑战。
我正在使用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];FXBlurView顶部时,UIScrollView我的成绩也很差。我相信这与添加模糊的方式有关。如果我没记错的话,Apple是在使用自己的模糊功能时直接访问GPU,这是我们开发人员无法做到的。因此,@ cprcrack解决方案实际上是这里的最佳解决方案。
                    警告:评论中的某人指出Apple拒绝使用此技术的应用程序。那对我没有发生,只是供您考虑。
这可能会让您感到惊讶,但是您可以使用UIToolbar,该工具包已经包含该标准效果(仅iOS 7+)。在您查看控制器的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 everythingviewDidLoad。-(void)viewDidLoad {[super viewDidLoad]; self.view = [[UIToolbar alloc] initWithFrame:CGRectZero]; 在我的情况下,我以编程方式(旧样式)布局视图。我赞成这种解决方案,因为UIToolbar继承了UIView,所以从根本上讲,我在此解决方案中看不到任何问题。在进行开发和测试此解决方案时,我将进行更多测试。
                    从iOS8开始,您可以使用UIBlurEffect。
UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];         UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
                    获得模糊叠加层的最佳新方法是使用新的iOS 8功能UIVisualEffectView。
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *bluredView = [[UIVisualEffectView alloc] initWithEffect:effect];
bluredView.frame = self.view.bounds;
[self.view addSubview:bluredView];UIBlurEffect支持三种样式。黑暗,光明和超轻。
您可以使用UIToolBar创建一个类,该类是UIView的子类,并在单独的视图控制器中实例化它。此方法演示了提供实时反馈(在这种情况下为AVCaptureSession)的半透明UIToolBar(由UIView子类化)。
YourUIView.h
#import <UIKit/UIKit.h>
@interface YourUIView : UIView
@property (nonatomic, strong) UIColor *blurTintColor;
@property (nonatomic, strong) UIToolbar *toolbar;
@endYourUIView.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后,继续创建一个类,该类是ViewController的子类。下面,我创建了一个使用AVCapture会话的类。您必须使用AVCaptureSession才能覆盖Apple的内置摄像头配置。因此,您可以覆盖YourUIView类中的半透明UIToolBar。
YourViewController.h
#import <UIKit/UIKit.h>
@interface YourViewController : UIViewController
@property (strong, nonatomic) UIView *frameForCapture;
@endYourViewController.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