ios - 如何在UIImagePickerController的自定义控件中使用不同模式之间的切换?

标签 ios uiimagepickercontroller

picker.showsCameraControls = NO;
picker.cameraOverlayView = someView;

由于我将向 showCameraControls 添加一些自定义 View ,那么如何在模式之间切换,就像 iPhone 的 native 应用程序在相机和录制之间切换一样,就像我想在相机和另一个带有按钮的相机之间切换一样,我该怎么做? 救命!

最佳答案

在您的自定义 View 中,您将通过一键设置选择器作为目标,并使用 takePicture 方法。然后,您将有另一个按钮,或开关,或者您想要进入自定义模式的方式,并且您将有一个按钮来开始/停止捕捉。这个按钮应该有 self 作为目标(self 作为您提供选择器的 View Controller )和自定义的toggleSnapping 方法。您还需要将自己设置为图像选择器的代表,以便在拍摄每张照片时收到通知。哦,还有一个 BOOL 实例变量,用于跟踪捕捉当前是否处于事件状态。那么你的toggleSnapping方法可能看起来像这样:

- (void)toggleSnapping
{
    isSnapping = !isSnapping; // (this will reverse NO to YES and vice-versa)
    [picker takePicture]; // starts taking 1st picture, delegate will take care of rest
    if (isSnapping) {
        // configure your button to show stop icon
    } else {
        // configure your button to show start snapping icon
    }
}

并且您需要实现选择器的委托(delegate)方法,如果 isSnapping 当前为 YES,您只需启动另一张图片即可:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // save the snapped picture to the camera roll

    if (isSnapping) { // if burst mode is on, take another picture
        [picker takePicture];
    }
}

关于ios - 如何在UIImagePickerController的自定义控件中使用不同模式之间的切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7020475/

相关文章:

ios - UITextContainerView 隐藏了 UITextView 的可点击链接

android - Xamarin Forms 直接从应用程序发送邮件

ios - UIImagePicker 始终以横向模式打开照片应用程序

objective-c - 隐藏 UIImagePickerControllerSourceTypceCamera 工具栏,但特定按钮?

ios - 在 SwiftUI 中根据文本高度自动调整 View 高度

ios - 使用 Swift 将类中的结构保存到 NSUserDefaults

javascript - 位置 : fixed; element doesn't work correctly on iOS 上的触摸事件

iPhone - 显示 UIImagePickerController

ios - "The file “IMG_xxxx.JPG” 无法打开,因为没有这样的文件。”

objective-c - 在没有图像选择器的情况下拍照(模态视图)