进入 UIImagePickerController 编辑模式

Posted

技术标签:

【中文标题】进入 UIImagePickerController 编辑模式【英文标题】:Entering UIImagePickerController editing mode 【发布时间】:2013-07-25 09:12:52 【问题描述】:

我使用UIImagePickerController (photoPicker) 用相机拍照,然后编辑这些照片 (allowEditing = YES)。用户可以通过photoPicker.view 中的按钮在相机和库之间切换,但我想在photoPicker 处于编辑模式时删除此按钮。

photoLibrarySourceType 中,选择器使用推送来显示编辑模式,因此可以使用这种方法:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

    if (navigationController == photoPicker) 
        NSLog(@"navigation ");
        if ([navigationController.viewControllers indexOfObject:viewController] == 1)
        
            // If second UIViewController, set your overlay.
            NSLog(@"editing");
        
    

但在cameraSourceType 中,相机和编辑模式之间没有导航。

【问题讨论】:

你找到解决方案了吗,我也有同样的问题:( 【参考方案1】:

我想出了一个小技巧,它对我有用。我还是有点新,所以请随意优化,因为我找不到其他方法。

基本思想是在默认相机按钮上创建一个不可见按钮,该按钮执行调用[uiimagepickercontroller takePicture]的方法

这是我的示例代码

@implementation myViewController

    UIImagePickerController *myImagePickerController; 
    UIButton * fakeCameraButton;




- (IBAction)showImagePicker:(id)sender

    // accessible camera validations implied
    myImagePickerController = [[UIImagePickerController alloc]init];
    myImagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;       
    myImagePickerController.showsCameraControls = YES;
    myImagePickerController.delegate=self;
    myImagePickerController.allowsEditing=YES; 

    CGFloat myViewHeight = 100; // you play around with the positions to get your desired frame size. This worked for me
    UIView * myView = [[UIView alloc] initWithFrame:CGRectMake(0, myImagePickerController.view.frame.size.height - myViewheight, picker.view.frame.size.width, myViewheight)];

   fakeCameraButton = [[UIButton alloc] initWithFrame:CGRectMake(myView.frame.size.width / 2 - 30, myView.frame.size.height/2-15, 60, 60)];// position it over the default camera button
   [fakeCameraButton addTarget:self action:@selector(cameraButtonPressed) forControlEvents:UIControlEventTouchUpInside];
   [fakeCameraButton setTitle:@"" forState:UIControlStateNormal];

   [myView addSubview:fakeCameraButton];
   myImagePickerController.cameraOverlayView = myView;
   [self presentViewController:myImagePickerController animated:YES completion:nil];




-(void)cameraButtonPressed

    // Make sure you check if camera is ready before this method. 
   [myImagePickerController takePicture];

    // you are in editing/preview mode here if allowsEditing = YES

    // you can remove all your custom overlay views by
    myImagePickerController.cameraOverlay = nil



 

就像我之前说的,请确保检查相机是否准备就绪。您可以在 *** 上找到有关如何操作的答案。

此代码可能很糟糕,因此欢迎编辑或替代解决方案。

我需要开发伙伴帮助我了解有关 ios 开发的更多信息并提出问题。有人感兴趣吗?

【讨论】:

以上是关于进入 UIImagePickerController 编辑模式的主要内容,如果未能解决你的问题,请参考以下文章

ViewController 生命周期 UINavigationController

如何从 webview 使用 UIImagePickerController

iPhone OS 3.0 中的 UIImagePickerController

iOS开发——打开手机相册,获取图片

如何使用 iphone 中的核心数据将图像存储到 sqlite? [复制]

如何进入Recovery模式 安卓手机进入Recovery模式方法大全