anthoprotic
anthoprotic

Reputation: 827

UIImagePickerController black opaque bottom bar

I need my view to have a Black Opaque bottom and top bar when taking a picture. I want it to look exactly like this:

https://i.sstatic.net/KO8Fy.jpg

This is actually what I have running my code on my iPhone 5 running iOS 7. But when I compiled my code on an iPhone 4S (iOS 7 too), the bottom bar becomes transparent - the view becomes a camera from top to bottom, like the camera app now. Even the "Take Picture" button becomes transparent, like SnapChat. I hate this. What's the setting I need to change to make the bottom bar become opaque on my iPhone 4S? I am using autolayout.

This is in my viewDidAppear:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        self.anImagePickerController = [UIImagePickerController new];
        self.anImagePickerController.delegate = self;
        self.anImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.anImagePickerController.showsCameraControls = YES;

        [self presentViewController:self.anImagePickerController animated:NO completion:Nil];
    }

Upvotes: 4

Views: 2566

Answers (3)

klcjr89
klcjr89

Reputation: 5902

Code below will do exactly what you want. I discovered this myself as I was wanting to do the exact same thing as you, and feel that rolling your own camera controller is completely unnecessary.

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
imagePicker.delegate = self;

 [self presentViewController:imagePicker animated:YES completion:^()
 {   
     for (UIView *subview in imagePicker.view.subviews)
     {
        if([NSStringFromClass([subview class]) isEqualToString:@"UINavigationTransitionView"])
        {
            UIView *theView = (UIView *)subview;

            for (UIView *subview in theView.subviews)
            {
               if([NSStringFromClass([subview class]) isEqualToString:@"UIViewControllerWrapperView"])
               {
                   UIView *theView = (UIView *)subview;

                    for (UIView *subview in theView.subviews)
                    {
                         if([NSStringFromClass([subview class]) isEqualToString:@"PLCameraView"])
                         {
                             UIView *theView = (UIView *)subview;

                             for (UIView *subview in theView.subviews)
                             {
                                 if([NSStringFromClass([subview class]) isEqualToString:@"CAMTopBar"])
                                 {
                                      subview.backgroundColor = [UIColor blackColor];
                                 }
                                 if([NSStringFromClass([subview class]) isEqualToString:@"CAMBottomBar"])
                                 {
                                      subview.backgroundColor = [UIColor blackColor];
                                 }
                                 if([NSStringFromClass([subview class]) isEqualToString:@"PLCropOverlay"])
                                 {
                                     UIView *theView = (UIView *)subview;

                                     for (UIView *subview in theView.subviews)
                                     {
                                         if([NSStringFromClass([subview class]) isEqualToString:@"PLCropOverlayBottomBar"])
                                         {
                                              UIView *theView = (UIView *)subview;

                                              for (UIView *subview in theView.subviews)
                                              {
                                                  if([NSStringFromClass([subview class]) isEqualToString:@"PLCropOverlayPreviewBottomBar"])
                                                  {
                                                      subview.backgroundColor = [UIColor blackColor];
                                                  }
                                              }
                                          }
                                      }
                                  }
                              }
                          }
                      }
                 }
             }
         }
     }
}];

Upvotes: 1

Léo Natan
Léo Natan

Reputation: 57040

I don't think you can modify the behavior of UIImagePickerController. It is likely removing the black bar due to not enough screen space on the smaller screen devices. If you insist on this behavior, you need to go the custom overlay method. You set showsCameraControls to NO, and provide a cameraOverlayView which will behave as you need it to. From your custom overlay view, when the user taps the button to take a picture, you call takePicture on the image picker controller.

You can see an example implementation of an overlay view in Apple's examples: https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010196

Upvotes: 1

matt
matt

Reputation: 534987

UIImagePickerController is a UINavigationController. The bar you are complaining about is the UINavigationController's toolbar. As you surely know, a toolbar is transparent (or at least translucent) by default on iOS 7.

Upvotes: 0

Related Questions