UIImagePickerController 关闭时弄乱标签栏框架

Posted

技术标签:

【中文标题】UIImagePickerController 关闭时弄乱标签栏框架【英文标题】:UIImagePickerController messing tabbar frame when dismissing 【发布时间】:2015-01-21 19:21:42 【问题描述】:

我正在尝试在 UITabBarController 内的 UIViewController 中显示 UIImagePickerController

SourceType 相机 MediaType kUTTypeMovie

呈现 UIImagePickerController 没有问题,但是当关闭 TabBar 时,TabBar 会向下移动一半高度,它只是有时会发生……其他情况下它会完美关闭。

override func viewDidLoad() 

    var test: UIButton = UIButton(frame:CGRectMake(140, 200, 100, 100))
    test.backgroundColor = UIColor.redColor()
    test.addTarget(self, action:"presentCamera", forControlEvents: .TouchDown)
    self.view.addSubview(test)


func presentCamera()
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)
        imag.mediaTypes = [kUTTypeMovie]
        imag.delegate = self
        imag.sourceType = UIImagePickerControllerSourceType.Camera;
        imag.videoQuality = UIImagePickerControllerQualityType.TypeMedium
        imag.videoMaximumDuration = 120
        imag.allowsEditing = false
        self.presentViewController(imag, animated: true, completion:println("showing"))
    



func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) 
    let library = ALAssetsLibrary()
    var videoTemp = info[UIImagePickerControllerMediaURL] as NSURL
    videoPath = videoTemp.relativePath
    UISaveVideoAtPathToSavedPhotosAlbum(videoPath, self, nil, nil)
    picker.dismissViewControllerAnimated(true, completion:
        println("video selected")
    )    


func imagePickerControllerDidCancel(picker: UIImagePickerController) 
    picker.dismissViewControllerAnimated(true, completion:
        println("canceled")
    )

它也显示此错误:

"对未渲染的视图进行快照会导致空白 快照。确保您的视图之前至少渲染过一次 屏幕更新后的快照或快照。”

以下是有关应用程序和错误外观的视频:

https://www.youtube.com/watch?v=o1BgLbZgsfw

【问题讨论】:

【参考方案1】:

这里已经问过了:

Redbar Noticed when dismissing UIImagePickerController

我还注意到关闭时的红色状态栏,使用此解决:

您应该在 .plist 中将“基于控制器的状态栏外观”值设置为 YES

【讨论】:

以上是关于UIImagePickerController 关闭时弄乱标签栏框架的主要内容,如果未能解决你的问题,请参考以下文章

UIImagePickerController、自定义 UIButton 和 AutoLayout

UIImagePickerController 实况照片

OCMock 模拟 UIImagePickerController

UIImagePickerController 图像没有改变

无法弹出 UIImagePickerController

为啥 UIImagePickerController 不能推入导航栈?