iOS,UIImagePickerController,有没有办法在不实现自定义控件的情况下检测用户何时点击拍照按钮? [英] iOS, UIImagePickerController, is there a way to detect when user taps the take picture button without implementing custom controls?

查看:31
本文介绍了iOS,UIImagePickerController,有没有办法在不实现自定义控件的情况下检测用户何时点击拍照按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 7.3,iOS 9.3.1

我想在用户即将拍照和编辑图片之后使用两个自定义叠加视图.要更改叠加层,我想知道 UIImagePickerControllerDelegate 是否有回调方法可以让我知道用户何时开始编辑图片,或者用户何时点击了拍照按钮.

I want to use two custom overlay views for when the user is about to take a picture and after while editing the picture. To change the overlay I would like to know if there is a callback method from the UIImagePickerControllerDelegate that will let me know when the user starts editing the picture, or when the user has tapped the take picture button.

我所知道的唯一方法是:

The only methods I know of are:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

我看过这里:UIImagePickerController with cameraOverlayView focusses when button点击叠加层如何知道我点击了拍照按钮";使用 UIImagePickeriOS - 在 UIImagePickerController CustomOverlayView 中点击按钮后拍照.

I have looked here: UIImagePickerController with cameraOverlayView focusses when button in overlay is tapped, How to know I tap "taking photo button" with UIImagePicker and iOS - Taking A Picture After Button Tap in UIImagePickerController CustomOverlayView.

或者也许有一种方法可以通过添加观察者从标准按钮获取点击事件.

Or perhaps there is a way to get the tap event from the standard button by adding an observer.

请帮忙!提前致谢.

推荐答案

Xcode 8.2.1, iOS10.2.1

在实施之前,请阅读早期版本的解决方案以了解基础知识.谢谢!问题是各种子视图的某些名称已从 iOS 9.3.1 更改为 iOS 10.2.1.

Before implementing please read the solution for earlier version to understand the basics. Thanks! The problem was that some of the names for various subviews have changed from iOS 9.3.1 to iOS 10.2.1.

这里是完整的代码(见下面的插入位置),它替换了下面的//代码在这里":

Here is the complete code (see below where to insert), that replaces "//Code goes here" below:

for (UIView *subviewImagePickerControllerView in self.imagePickerController.view.subviews)
{
    if ([subviewImagePickerControllerView.class.description isEqualToString:@"UINavigationTransitionView"])
    {
        for (UIView *subviewUINavigationTransitionView in subviewImagePickerControllerView.subviews)
        {
            if ([subviewUINavigationTransitionView.class.description isEqualToString:@"UIViewControllerWrapperView"])
            {
                for (UIView *subviewUIViewControllerWrapperView in subviewUINavigationTransitionView.subviews)
                {
                    if ([subviewUIViewControllerWrapperView.class.description isEqualToString:@"CAMCameraViewControllerContainerView"])
                    {
                        for (UIView *subviewCAMCameraViewControllerContainerView in subviewUIViewControllerWrapperView.subviews)
                        {
                            if ([subviewCAMCameraViewControllerContainerView.class.description isEqualToString:@"CAMViewfinderView"])
                            {
                                for (UIView *subviewCAMViewfinderView in subviewCAMCameraViewControllerContainerView.subviews)
                                {
                                    if ([subviewCAMViewfinderView.class.description isEqualToString:@"CAMBottomBar"])
                                    {
                                        for (UIView *subviewCAMBottomBar in subviewCAMViewfinderView.subviews)
                                        {
                                            if ([subviewCAMBottomBar.class.description isEqualToString:@"CUShutterButton"] && [subviewCAMBottomBar.class isSubclassOfClass:[UIButton class]])
                                            {
                                                UIButton *shutterButton = (UIButton *)subviewCAMBottomBar;

                                                [shutterButton addTarget:self action:@selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
                                            }
                                            else
                                            {
                                                nil;
                                            }
                                        }
                                    }
                                }

                            }
                            else if ([subviewCAMCameraViewControllerContainerView.class.description isEqualToString:@"PLCropOverlay"])
                            {
                                for (UIView *subviewPLCropOverlay in subviewCAMCameraViewControllerContainerView.subviews)
                                {
                                    if ([subviewPLCropOverlay.class.description isEqualToString:@"PLCropOverlayBottomBar"])
                                    {
                                        for (UIView *subviewPLCropOverlayBottomBar in subviewPLCropOverlay.subviews)
                                        {
                                            if ([subviewPLCropOverlayBottomBar.class.description isEqualToString:@"PLCropOverlayPreviewBottomBar"])
                                            {
                                                for (UIView *itemPLCropOverlayPreviewBottomBar in subviewPLCropOverlayBottomBar.subviews)
                                                {
                                                    if ([itemPLCropOverlayPreviewBottomBar.class isSubclassOfClass:[UIButton class]])
                                                    {
                                                        UIButton *buttonPLCropOverlay = (UIButton *)itemPLCropOverlayPreviewBottomBar;

                                                        if ([buttonPLCropOverlay.titleLabel.text isEqualToString:@"Retake"])
                                                        {
                                                            UIButton *retakeButton = buttonPLCropOverlay;

                                                            [retakeButton addTarget:self action:@selector(touchUpInsideButtonRetake) forControlEvents:UIControlEventTouchUpInside];
                                                        }
                                                        else
                                                        {
                                                            nil;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        nil;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                nil;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        nil;
                                    }
                                }
                            }
                            else
                            {
                                nil;
                            }
                        }
                    }
                    else
                    {
                        nil;
                    }
                }
            }
            else
            {
                nil;
            }
        }
    }
    else
    {
        nil;
    }
}

Xcode 7.3,iOS9.3.1

我必须让这个工作,所以我花了很多时间来解决这个问题.

I had to get this working, so I spent a lot of time figuring this out.

它的要点是,我在 UIImagePickerController 出现后深入视图层次结构,寻找 CMKShutterButton 和标题为Retake"的重拍按钮,然后我将一个选择器附加到按钮的操作上,就像这样......

The gist of it is, I drill down the view hierarchy after the UIImagePickerController was presented, looking for CMKShutterButton and the retake button with a title of "Retake", then I attach a selector to the buttons' action, like so...

[shutterButton addTarget:self action:@selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];

[retakeButton addTarget:self action:@selector(touchUpInsideButtonRetake) forControlEvents:UIControlEventTouchUpInside];

将下面的代码放入在您的图像选择器出现后调用的完成块中:

Drop the code below into the completion block that is called after your image picker is presented:

[self presentViewController:self.imagePickerController animated:true completion:^(void){

     //Code goes here

}

这里是完整的代码,它取代了上面的//代码在这里":

Here is the complete code, that replaces "//Code goes here" above:

for (UIView *subviewImagePickerControllerView in self.imagePickerController.view.subviews)
{
    if ([subviewImagePickerControllerView.class.description isEqualToString:@"UINavigationTransitionView"])
    {
        for (UIView *subviewUINavigationTransitionView in subviewImagePickerControllerView.subviews)
        {
            if ([subviewUINavigationTransitionView.class.description isEqualToString:@"UIViewControllerWrapperView"])
            {
                for (UIView *subviewUIViewControllerWrapperView in subviewUINavigationTransitionView.subviews)
                {
                    if ([subviewUIViewControllerWrapperView.class.description isEqualToString:@"PLImagePickerCameraView"])
                    {
                        for (UIView *subviewPLImagePickerCameraView in subviewUIViewControllerWrapperView.subviews)
                        {
                            if ([subviewPLImagePickerCameraView.class.description isEqualToString:@"CMKBottomBar"])
                            {
                                for (UIView *itemCMKBottomBar in subviewPLImagePickerCameraView.subviews)
                                {
                                    if ([itemCMKBottomBar.class.description isEqualToString:@"CMKShutterButton"] && [itemCMKBottomBar.class isSubclassOfClass:[UIButton class]])
                                    {
                                        UIButton *shutterButton = (UIButton *)itemCMKBottomBar;

                                        [shutterButton addTarget:self action:@selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
                                    }
                                    else
                                    {
                                        nil;
                                    }
                                }
                            }
                            else if ([subviewPLImagePickerCameraView.class.description isEqualToString:@"PLCropOverlay"])
                            {
                                for (UIView *subviewPLCropOverlay in subviewPLImagePickerCameraView.subviews)
                                {
                                    if ([subviewPLCropOverlay.class.description isEqualToString:@"PLCropOverlayBottomBar"])
                                    {
                                        for (UIView *subviewPLCropOverlayBottomBar in subviewPLCropOverlay.subviews)
                                        {
                                            if ([subviewPLCropOverlayBottomBar.class.description isEqualToString:@"PLCropOverlayPreviewBottomBar"])
                                            {
                                                for (UIView *itemPLCropOverlayPreviewBottomBar in subviewPLCropOverlayBottomBar.subviews)
                                                {
                                                    if ([itemPLCropOverlayPreviewBottomBar.class isSubclassOfClass:[UIButton class]])
                                                    {
                                                        UIButton *buttonPLCropOverlay = (UIButton *)itemPLCropOverlayPreviewBottomBar;

                                                        if ([buttonPLCropOverlay.titleLabel.text isEqualToString:@"Retake"])
                                                        {
                                                            UIButton *retakeButton = buttonPLCropOverlay;

                                                            [retakeButton addTarget:self action:@selector(touchUpInsideButtonRetake) forControlEvents:UIControlEventTouchUpInside];
                                                        }
                                                        else
                                                        {
                                                            nil;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        nil;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                nil;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        nil;
                                    }
                                }
                            }
                            else
                            {
                                nil;
                            }
                        }
                    }
                    else
                    {
                        nil;
                    }
                }
            }
            else
            {
                nil;
            }
        }
    }
    else
    {
        nil;
    }
} 

这是我要附加的方法,它进入呈现图像选择器控制器的视图控制器:

And here is the method I am attaching, which goes in the view controller that is presenting the image picker controller:

- (void)touchUpInsideCMKShutterButton
{
    NSLog(@"Take");
}

- (void)touchUpInsideButtonRetake
{
    NSLog(@"Re-take");
}

希望这对某人有所帮助!谢谢.

Hope this helps someone! Thanks.

这篇关于iOS,UIImagePickerController,有没有办法在不实现自定义控件的情况下检测用户何时点击拍照按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆