首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在UIImagePickerController中禁用视频捕获

UIImagePickerController中禁用视频捕获,可以通过设置mediaTypes属性来实现。以下是一个简单的示例:

代码语言:swift
复制
import UIKit

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        let imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self
        imagePickerController.sourceType = .camera
        imagePickerController.mediaTypes = ["public.image"]

        present(imagePickerController, animated: true, completion: nil)
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
        picker.dismiss(animated: true, completion: nil)

        if let image = info[.originalImage] as? UIImage {
            // 处理图片
        }
    }

    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        picker.dismiss(animated: true, completion: nil)
    }
}

在这个示例中,我们设置了mediaTypes属性为["public.image"],这意味着UIImagePickerController只能捕获图片,而不能捕获视频。这样,在UIImagePickerController中,用户将无法录制视频。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

IOS移动开发从入门到精通 视图UIView、层CALayer(2)

或者修改 rootViewController参数 2、弹出框: import UIKit class ViewController:UIViewController { var label:UILabel! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.brown label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = ”” self.view.addSubview(label) let button = UIButton(frame:CGRect(x:40, y:180,width:240, height:44)) button.setTitle(“打开新的视图控制器”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview(button) } func openViewController() { let newViewController = NewViewController() newViewController.labelTxt = “传递的参数!” newViewController.viewController = self self.present(newViewController, animated:true,completion:nil) } }

01
领券