Chisx
Chisx

Reputation: 1986

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

Upvotes: 5

Views: 1298

Answers (3)

Olav
Olav

Reputation: 9

I found this will disable the zoom feature.

imagePicker.view.isUserInteractionEnabled = false

The above knocks out user interaction for the camera.

Here is what worked for me finally.

Add the cameraOverlay as a subview to the picker.

if let overlay = overlayViewController?.view {
           imagePicker.view.addSubview(overlay)
        }

Upvotes: 0

Mr.KLD
Mr.KLD

Reputation: 2742

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.

Upvotes: 1

Rufus Mall
Rufus Mall

Reputation: 589

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

Upvotes: 1

Related Questions