Skip to main content
added 6878 characters in body
Source Link
serge-k
  • 3.5k
  • 2
  • 27
  • 56

Xcode 8.2.1, iOS10.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

Xcode 7.3, iOS9.3.1

Xcode 8.2.1, iOS10.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

added 3536 characters in body
Source Link
serge-k
  • 3.5k
  • 2
  • 27
  • 56

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 buttonsbuttons' action, like so...

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

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

Here isDrop the complete code below into the completion block that is called after your image picker is presented:

[self presentViewController:controllerself.imagePickerController animated:true completion:^(void){
    
    for (UIView *transitionView in controller.view.subviews)
    {
        if ([transitionView.class.description isEqualToString:@"UINavigationTransitionView"])
        {
            for (UIView *wrapperView in transitionView.subviews)
            {
                if ([wrapperView.class.description isEqualToString:@"UIViewControllerWrapperView"])
                {
                    for (UIView *imagePickerView in wrapperView.subviews)
                    {
                        if ([imagePickerView.class.description isEqualToString:@"PLImagePickerCameraView"])
                        {
                            for (UIView *bottomBar in imagePickerView.subviews)
                            {
                                if ([bottomBar.class.description isEqualToString:@"CMKBottomBar"])
                                {
                                    for (UIView *bottomBarItem in bottomBar.subviews)
                                    {
                                        if ([bottomBarItem.class.description isEqualToString:@"CMKShutterButton"] && [bottomBarItem.class isSubclassOfClass:[UIButton class]])
                                        {
                                            UIButton *shutterButton = (UIButton *)bottomBarItem;
                                            
                                            [shutterButton addTarget:self action:@selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
                                        }
                                        else
                                        {
                                            nil;
                                        }
                                    }
                                }
                                else
                                {
                                    nil;
                                }
                            }
                        }
                        else
                        {
                            nil;
                        }
                    }
                }
                else
                {
                    nil;
                }
            }
        }
        else
        {
            nil;
      //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;
    }
} 
- (void)touchUpInsideCMKShutterButton
{
    NSLog(@"touched"@"Take");
}

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

The gist of it is, I drill down the view hierarchy after the UIImagePickerController was presented, looking for CMKShutterButton, then I attach a selector to the buttons action, like so...

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

Here is the complete code:

[self presentViewController:controller animated:true completion:^(void){
    
    for (UIView *transitionView in controller.view.subviews)
    {
        if ([transitionView.class.description isEqualToString:@"UINavigationTransitionView"])
        {
            for (UIView *wrapperView in transitionView.subviews)
            {
                if ([wrapperView.class.description isEqualToString:@"UIViewControllerWrapperView"])
                {
                    for (UIView *imagePickerView in wrapperView.subviews)
                    {
                        if ([imagePickerView.class.description isEqualToString:@"PLImagePickerCameraView"])
                        {
                            for (UIView *bottomBar in imagePickerView.subviews)
                            {
                                if ([bottomBar.class.description isEqualToString:@"CMKBottomBar"])
                                {
                                    for (UIView *bottomBarItem in bottomBar.subviews)
                                    {
                                        if ([bottomBarItem.class.description isEqualToString:@"CMKShutterButton"] && [bottomBarItem.class isSubclassOfClass:[UIButton class]])
                                        {
                                            UIButton *shutterButton = (UIButton *)bottomBarItem;
                                            
                                            [shutterButton addTarget:self action:@selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
                                        }
                                        else
                                        {
                                            nil;
                                        }
                                    }
                                }
                                else
                                {
                                    nil;
                                }
                            }
                        }
                        else
                        {
                            nil;
                        }
                    }
                }
                else
                {
                    nil;
                }
            }
        }
        else
        {
            nil;
        }
    }
}];
- (void)touchUpInsideCMKShutterButton
{
    NSLog(@"touched");
}

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;
    }
} 
- (void)touchUpInsideCMKShutterButton
{
    NSLog(@"Take");
}

- (void)touchUpInsideButtonRetake
{
    NSLog(@"Re-take");
}
Source Link
serge-k
  • 3.5k
  • 2
  • 27
  • 56

Xcode 7.3, iOS9.3.1

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

The gist of it is, I drill down the view hierarchy after the UIImagePickerController was presented, looking for CMKShutterButton, then I attach a selector to the buttons action, like so...

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

Here is the complete code:

[self presentViewController:controller animated:true completion:^(void){
    
    for (UIView *transitionView in controller.view.subviews)
    {
        if ([transitionView.class.description isEqualToString:@"UINavigationTransitionView"])
        {
            for (UIView *wrapperView in transitionView.subviews)
            {
                if ([wrapperView.class.description isEqualToString:@"UIViewControllerWrapperView"])
                {
                    for (UIView *imagePickerView in wrapperView.subviews)
                    {
                        if ([imagePickerView.class.description isEqualToString:@"PLImagePickerCameraView"])
                        {
                            for (UIView *bottomBar in imagePickerView.subviews)
                            {
                                if ([bottomBar.class.description isEqualToString:@"CMKBottomBar"])
                                {
                                    for (UIView *bottomBarItem in bottomBar.subviews)
                                    {
                                        if ([bottomBarItem.class.description isEqualToString:@"CMKShutterButton"] && [bottomBarItem.class isSubclassOfClass:[UIButton class]])
                                        {
                                            UIButton *shutterButton = (UIButton *)bottomBarItem;
                                            
                                            [shutterButton addTarget:self action:@selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
                                        }
                                        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(@"touched");
}

Hope this helps someone! Thanks.