UIImagePicker只填充屏幕的上半部分

时间:2015-01-31 22:09:06

标签: ios swift uiimagepickercontroller

我正在尝试仅在屏幕的上半部分显示相机,而我的代码没有正确调整相机的大小。我正在尝试将视图添加到屏幕的上半部分,然后让相机的cameraOverlayView属性符合该视图的框架。然而,无论我尝试什么,相机仍然以全屏模式显示。如果有人能告诉我我做错了什么,我真的很感激。谢谢!

    // Setting Up The Camera View

    cameraView = UIView(frame: CGRectMake(0.0, 0.0, view.bounds.width, view.bounds.width))
    view.addSubview(cameraView)

    // Setting Up The Camera

    var cam = UIImagePickerController()
    cam.delegate = self
    cam.allowsEditing = false
    cam.videoMaximumDuration = 7
    cam.videoQuality = UIImagePickerControllerQualityType.TypeMedium
    cam.mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(UIImagePickerControllerSourceType.Camera)!
    cam.sourceType = UIImagePickerControllerSourceType.Camera
    cam.cameraDevice = UIImagePickerControllerCameraDevice.Rear
    cam.cameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video
    cam.cameraFlashMode = UIImagePickerControllerCameraFlashMode.Off
    cam.showsCameraControls = true

    cam.cameraOverlayView = cameraView
    cam.cameraOverlayView?.frame = cameraView.frame

    camera = cam

    self.presentViewController(camera, animated: false, completion: nil)

1 个答案:

答案 0 :(得分:0)

我认为您不想使用UIImagePickerController完成您想要做的事情。如果您想完全自定义相机,AVFoundation就是您想要使用的。你可以在这里阅读https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW2

P.S。它不是最简单的框架