Enabling the photo library button on the UIImagePickerController

后端 未结 5 1972
庸人自扰
庸人自扰 2021-02-02 13:26

Does anyone know how to enable the photo album button on the UIImagePickerController when its in the camera mode? Like how the camera app on on the iphone can toggle between ima

5条回答
  •  你的背包
    2021-02-02 14:31

    This can be done via the following lines:

    - (void) navigationController: (UINavigationController *) navigationController  willShowViewController: (UIViewController *) viewController animated: (BOOL) animated {
        if (imagePickerController.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
            UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(showCamera:)];
            viewController.navigationItem.rightBarButtonItems = [NSArray arrayWithObject:button];
        } else {
            UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle:@"Library" style:UIBarButtonItemStylePlain target:self action:@selector(showLibrary:)];
            viewController.navigationItem.leftBarButtonItems = [NSArray arrayWithObject:button];
            viewController.navigationItem.title = @"Take Photo";
            viewController.navigationController.navigationBarHidden = NO; // important
        }
    }
    
    - (void) showCamera: (id) sender {
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    }
    
    - (void) showLibrary: (id) sender {
        imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    

提交回复
热议问题