zoukankan      html  css  js  c++  java
  • 截取UIImagePickerController的拍照事件

    前言 :

        iOS拍照可以用AVCaptureSession和UIImagePickerController来实现,两者都可以自定义拍照界面,UIImagePickerController有iOS原生的拍照界面,用起来很简单,但是有时候回需要在拍照界面加点文字说明,边框之类的修饰views,在用户点击拍照按钮后,隐藏这些修饰views。

     在调起UIImagePickerController 来拍照的时候,如下图,添加了拍摄边框和文字说明


    解决方案:

    在模态推出UIImagePickerController的时候,viewController遵循UINavigationControllerDelegate, 会走这个代理方法

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

    //里面能获取到视图的层级关系

    viewController就是 CAMImagePickerCameraViewController

    }

    此时查看图层关系

    拍照按钮在CAMBottomBar上

    重拍按钮在PLCropOverlayPreviewBottomBar,而PLCropOverlayPreviewBottomBar又在PLCropOverlayBottomBar

    思路 : 找到拍照按钮和重拍按钮,给两个按钮添加事件。

    代码:

    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

        for (UIView *tmpView in viewController.view.subviews) {

            NSLog(@"tmpView.subviews_%@", tmpView.subviews);

            NSArray *tmpViewSubviews = tmpView.subviews;

            [tmpViewSubviews enumerateObjectsUsingBlock:^(UIView   * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

                if ([[[obj class]description]isEqualToString:@"CAMBottomBar"]) {

                    for (UIView *tmpView3 in obj.subviews) {

                        NSLog(@"CAMBottomBar.subviews_%@", obj.subviews);

                        if ( [[[tmpView3 class]description]isEqualToString:@"CUShutterButton"]) {

                            //拍照按钮

                            UIButton *shutButton = (UIButton *)tmpView3;

                            @weakify(self);

                            [[shutButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {

                                @strongify(self);

                                self.horizontalScreenPromptsView.hidden = YES;

                                self.promptslabel.text = @"";

                            }];

                            break;

                        }

                    }

                }

                if ([[[obj class]description]isEqualToString:@"PLCropOverlayBottomBar"]) {

                    for (UIView *tmpView3 in obj.subviews) {

                        NSLog(@"PLCropOverlayBottomBar%@", obj.subviews);

                        if ( [[[tmpView3 class]description]isEqualToString:@"PLCropOverlayPreviewBottomBar"]) {

                            for (UIView *tmpView4 in tmpView3.subviews) {

                                NSLog(@"PLCropOverlayPreviewBottomBar%@", tmpView4.subviews);

                               //重拍按钮

                                if ( [[[tmpView4 class]description]isEqualToString:@"UIButton"]) {

                                    UIButton *recameraButton = (UIButton *)tmpView4;

                                    @weakify(self);

                                    [[recameraButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {

                                        @strongify(self);

                                            self.horizontalScreenPromptsView.hidden = NO;

                                            self.promptslabel.text =@"请将手机横置拍摄";

                                    }];

                                    break;

                                }

                            }

                            break;

                        }

                    }

                }

            }];

    }

    结束

  • 相关阅读:
    36.百马百担问题。有100匹马,驮100担货,大马驮3担,中马驮2担,两匹小马驮1担,问有大中小马多少匹,共有多少组解?
    35.鸡兔同笼问题:今有雉兔同笼,上有三十五头,下有九十四足,问雉兔各几何?
    34.设s=1+1/2+1/3+…+1/n,求与8最接近的s的值及与之对应的n值
    33.求1*2+2*3+3*4+……前n项的和
    32.求1+(1+2)+(1+2+3)+(1+2+3+4)+……的前n项的和
    31.假定2007年的一月一日是星期一,输入一个时间(包含年、月、日),求出它是星期几。
    vue-cli3 一直运行 /sockjs-node/info?t= 解决方案
    python pdf转word
    window django-https 证书
    Docker技术应用场景(转载)
  • 原文地址:https://www.cnblogs.com/pengjuwang/p/8875672.html
Copyright © 2011-2022 走看看