• [翻译] DBCamera 轻量级定制摄像头


    DBCamera 轻量级定制摄像头

    https://github.com/danielebogo/DBCamera

    DBCamera is a simple custom camera with AVFoundation.

    DBCamera使用了AVFoundation框架并简单的定制了摄像头.

    Getting Started

    Installation

    The recommended approach for installating DBCamera is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.16.0 using Git >= 1.8.0 installed via Homebrew.

    推荐你使用CocoaPods安装.

    Integration

    DBCamera has a simple integration:

    DBCamera模块化很简单:

    #import "DBCameraViewController.h"
    #import "DBCameraContainer.h"
    
    //Add DBCameraViewControllerDelegate protocol
    @interface RootViewController () <DBCameraViewControllerDelegate>
    
    //Present DBCameraViewController with different behaviours
    
    - (void) openCamera
    {
        DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc] initWithDelegate:self];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
        [nav setNavigationBarHidden:YES];
        [self presentViewController:nav animated:YES completion:nil];
    }
    
    - (void) openCameraWithoutSegue
    {
        DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
        DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
        [cameraController setUseCameraSegue:NO];
        [container setCameraViewController:cameraController];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
        [nav setNavigationBarHidden:YES];
        [self presentViewController:nav animated:YES completion:nil];
    }
    
    - (void) openCameraWithoutContainer
    {
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[DBCameraViewController initWithDelegate:self]];
        [nav setNavigationBarHidden:YES];
        [self presentViewController:nav animated:YES completion:nil];
    }
    
    //Use your captured image
    #pragma mark - DBCameraViewControllerDelegate
    
    - (void) captureImageDidFinish:(UIImage *)image withMetadata:(NSDictionary *)metadata
    {
        [_imageView setImage:image];
        [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
    }
    

    By default, DBCameraViewController has another controller to display the image preview. When you create DBCameraViewController instance, you can set useCameraSegue: NO, to avoid it.

    默认情况下,DBCameraViewController有一个其他的controller来展示图片列表,当你创建这个DBCameraViewController实例时,你可以手动设置关闭它.

    - (void) openCameraWithoutSegue
    {
        DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
        DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
        [cameraController setUseCameraSegue:NO];
        [container setCameraViewController:cameraController];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
        [nav setNavigationBarHidden:YES];
        [self presentViewController:nav animated:YES completion:nil];
    }
    

    Customizing the camera

    Basic

    For simple customizations, you can customize the built-in camera view by sending a cameraSettingsBlock to the view controller.

    对于简单的定制,你可以给这个controller传递一个cameraSettingsBlock来实现内置照相机view的定制.

    #import "DBCameraView.h"
    - (void)openCameraWithSettings:(CDVInvokedUrlCommand*)command
    {
        DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc]
            initWithDelegate:self
            cameraSettingsBlock:^(DBCameraView *cameraView) {
                [cameraView.gridButton setHidden:YES];
            }];
    
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
        [nav setNavigationBarHidden:YES];
        [self presentViewController:nav animated:YES completion:nil];
    }
    

    Advanced

    You can also create a custom interface, using a subclass of DBCameraView

    当然,你也可以自己创建一个界面,通过继承DBCameraView子类的方式来实现.

    #import "DBCameraView.h"
    
    @interface CustomCamera : DBCameraView
    - (void) buildInterface;
    @end
    
    #import "CustomCamera.h"
    
    @interface CustomCamera ()
    @property (nonatomic, strong) UIButton *closeButton;
    @property (nonatomic, strong) CALayer *focusBox, *exposeBox;
    @end
    
    @implementation CustomCamera
    
    - (void) buildInterface
    {
        [self addSubview:self.closeButton];
    
        [self.previewLayer addSublayer:self.focusBox];
        [self.previewLayer addSublayer:self.exposeBox];
    
        [self createGesture];
    }
    
    - (UIButton *) closeButton
    {
        if ( !_closeButton ) {
            _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [_closeButton setBackgroundColor:[UIColor redColor]];
            [_closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
            [_closeButton setFrame:(CGRect){ CGRectGetMidX(self.bounds) - 15, 17.5f, 30, 30 }];
            [_closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
        }
    
        return _closeButton;
    }
    
    - (void) close
    {
        if ( [self.delegate respondsToSelector:@selector(closeCamera)] )
            [self.delegate closeCamera];
    }
    
    #pragma mark - Focus / Expose Box
    
    - (CALayer *) focusBox
    {
        if ( !_focusBox ) {
            _focusBox = [[CALayer alloc] init];
            [_focusBox setCornerRadius:45.0f];
            [_focusBox setBounds:CGRectMake(0.0f, 0.0f, 90, 90)];
            [_focusBox setBorderWidth:5.f];
            [_focusBox setBorderColor:[[UIColor whiteColor] CGColor]];
            [_focusBox setOpacity:0];
        }
    
        return _focusBox;
    }
    
    - (CALayer *) exposeBox
    {
        if ( !_exposeBox ) {
            _exposeBox = [[CALayer alloc] init];
            [_exposeBox setCornerRadius:55.0f];
            [_exposeBox setBounds:CGRectMake(0.0f, 0.0f, 110, 110)];
            [_exposeBox setBorderWidth:5.f];
            [_exposeBox setBorderColor:[[UIColor redColor] CGColor]];
            [_exposeBox setOpacity:0];
        }
    
        return _exposeBox;
    }
    
    - (void) drawFocusBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
    {
        [super draw:_focusBox atPointOfInterest:point andRemove:remove];
    }
    
    - (void) drawExposeBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
    {
        [super draw:_exposeBox atPointOfInterest:point andRemove:remove];
    }
    
    @end
    
    //Present DBCameraViewController with a custom view.
    @interface RootViewController () <DBCameraViewControllerDelegate>
    
    - (void) openCustomCamera
    {
        CustomCamera *camera = [CustomCamera initWithFrame:[[UIScreen mainScreen] bounds]];
        [camera buildInterface];
    
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[DBCameraViewController alloc] initWithDelegate:self cameraView:camera]];
        [nav setNavigationBarHidden:YES];
        [self presentViewController:nav animated:YES completion:nil];
    }
    

  • 相关阅读:
    完美图解教程 Linux环境VNC服务安装、配置与使用
    c语言中<stdbool.h>的使用
    UNIX文件结构(转自UNIX/AIX操作系统基础教程)
    umask
    在AIX环境为Oracle表空间增加裸设备(逻辑卷)
    面的面积大小合线的长度的判断。
    不用新浪博客了。以后的日常感悟也在这里写了, 新浪太烂了。 (感叹也没用,什么都写不出来。 )
    轴心工具的做法。
    选择因素随机的判断。
    上面发的那个完整版变量还有问题,难道我不是用英文输入法, 电脑不说谎 ,看来我是大意了。下面是最终版。
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3746910.html
Copyright © 2020-2023  润新知