iOS 7 UIImagePickerController navigationbar overla

2019-05-07 00:06发布

I ran into a problem accessing photo library in iOS7 (iOS6 is OK). It seems navigation bar overlaps the photo album view, I tried to set picker.edgesForExtendedLayout = UIRectEdgeNone; but it doesn't work.

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    picker.edgesForExtendedLayout = UIRectEdgeNone;
}

[self presentViewController:picker animated:YES completion:nil];

Look at my screenshot

enter image description here

3条回答
在下西门庆
2楼-- · 2019-05-07 00:29

This works for me:

UIImagePickerController set translucent = NO to navigation Bar

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.navigationController.navigationBar.translucent = NO;

After this, implement this code in your UIImagePickerController delegate:

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if ([navigationController isKindOfClass:[UIImagePickerController class]])
    {        
        viewController.navigationController.navigationBar.translucent = NO;
        viewController.edgesForExtendedLayout = UIRectEdgeNone;
    }
}
查看更多
爷的心禁止访问
3楼-- · 2019-05-07 00:39

Swift version of the above answer:

func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
        if navigationController.isKindOfClass(UIImagePickerController.self) {
            viewController.navigationController!.navigationBar.translucent = false
            viewController.edgesForExtendedLayout = .None
        }
    }
查看更多
戒情不戒烟
4楼-- · 2019-05-07 00:52

As user2192708 mentioned, I think the main issue here is changing the default translucent property of the picker navigationBar and I'm not sure you need to change anything else:

picker.navigationBar.translucent = NO

This will cause the the navigation bar to use the UINavigationBar appearance if you set this somewhere in your app or the "default" if not.

查看更多
登录 后发表回答