Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Zoom slider in UIImagePickerController

Im having trouble accessing the Zoom slider that appears by default in an UIImagePickerController. This doesn't seem accessible and I must hide it because it is popping up over my cameraOverlay view in my UIImagePickerController. Can someone tell me how I might hide the zoom slider that appears when the user pinchs and "zooms"?

Here is what the slider looks like:

PS this is not my custom camera. This is just an image of the slider that is appearing over my cameraOverlay

like image 393
Chisx Avatar asked Oct 31 '22 22:10

Chisx


2 Answers

I recently ran into this problem thanks to iOS 10.0. After spending significant time googling and not coming up with anything that worked - I came up with my own solution:

myVC.PresentViewController (_imagePicker, false, ()=>_imagePicker.View.Subviews[0].Subviews[0].Subviews[0].Subviews[0].Subviews[1].RemoveFromSuperview();

Essentially once the picker view has been presented - "_imagePicker.View.Subviews[0].Subviews[0].Subviews[0].Subviews[0].Subviews1.RemoveFromSuperview();" will be executed to remove the slider view from the camera.

This is likely to break in a future iOS update - so I don't recommend it for production apps. If you are doing a lot of custom camera stuff - it is advisable you use the AVFoundation framework.

Someone should raise a bug with apple that in iOS 10 "imagePicker.ShowsCameraControls = NO;" doesn't actually remove ALL the camera controls.

If you ever need to work out how to do something similar in the future you can use: the "Debug View Hierarchy" button in Xcode to view the viewHierachy and then click on the component you want to remove/guess by looking at the view names:

Example hierarchy path

In this case, the view that I wanted to remove was the "CAMViewfinderView". Hope this helps!

Note, my code was written in CSharp (Xamarin.IOS) but the same thing will work in objective-c - just slightly different syntax.

-Rufus

like image 116
Rufus Mall Avatar answered Nov 15 '22 05:11

Rufus Mall


I guess found the best answer to this issue: The zoom slider is a UISlider, if your imagePickerController's view property contains a UISlider down its subviews, you can set its alpha to zero. This issue happens if you upgrade to iOS10.

func subviews(_ view: UIView) -> [UIView] {
    return view.subviews + view.subviews.flatMap { subviews($0) }
}

let myViews = subviews(imagePickerController.view)
for view in myViews {
    if view is UISlider {
        view.alpha = 0.0
    }
}

I hope this helps.

like image 42
Mr.KLD Avatar answered Nov 15 '22 05:11

Mr.KLD