Ios,启动时相机冻结(黑屏)

时间:2014-10-03 16:20:57

标签: ios swift camera

所以我的相机冻结有问题。当它第一次被调用时它工作得很好。并在按钮上显示我的图像。但是,如果我回到相同的按钮再次呼叫相机,或者调用相机的页面上的任何其他按钮,它会启动相机但不是黑屏。相机实际上并没有出现它。这是我正在使用的代码......帮助会很棒。

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) {


    let image = info[UIImagePickerControllerOriginalImage] as UIImage
    pickedImage = image

    if let buttonToSet = buttonToSet {
        switch buttonToSet {
        case .Button1 :
            p1Image = pickedImage
            p1ImageButton.setImage(pickedImage, forState: UIControlState.Normal)
        case .Button2 :
            p2Image = pickedImage
            p2ImageButton.setImage(pickedImage, forState: UIControlState.Normal)
        case .Button3 :
            p3Image = pickedImage
            p3ImageButton.setImage(pickedImage, forState: UIControlState.Normal)
        case .Button4 :
            p4Image = pickedImage
            p4ImageButton.setImage(pickedImage, forState: UIControlState.Normal)

        }
    }


    self.dismissViewControllerAnimated(true, completion: nil)
    scrollView.setContentOffset(CGPointMake(0, -65), animated: true)


}

func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    dismissViewControllerAnimated(true, completion: nil)
    scrollView.setContentOffset(CGPointMake(0, -65), animated: true)
}

func promptForSource(){
    let actionSheet = UIActionSheet(title: "Image Source", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Camera", "Photo Roll")

    actionSheet.showInView(self.view)

}

func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {
    if buttonIndex != actionSheet.cancelButtonIndex {

        if buttonIndex != actionSheet.firstOtherButtonIndex {

            promptForCamera()
        }
        else{
            promptForPhotoRoll()
        }

    }
}

func promptForCamera(){
    let controller = UIImagePickerController()
    controller.sourceType = UIImagePickerControllerSourceType.Camera
    controller.delegate = self
    presentViewController(controller, animated: true, completion: nil)
}

func promptForPhotoRoll(){
    let controller = UIImagePickerController()
    controller.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    controller.delegate = self
    presentViewController(controller, animated: true, completion: nil)
}


@IBAction func p1PhotoTapped(sender: AnyObject) {
    buttonToSet = .Button1

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
        promptForSource()



    }else{
        promptForPhotoRoll()
    }


}


@IBAction func p2PhotoTapped(sender: AnyObject) {
    buttonToSet = .Button2
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
        promptForSource()



    }else{
        promptForPhotoRoll()
    }

}


@IBAction func p3PhotoTapped(sender: AnyObject) {
    buttonToSet = .Button3
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
        promptForSource()



    }else{
        promptForPhotoRoll()
    }

}

@IBAction func p4PhotoTapped(sender: AnyObject) {
    buttonToSet = .Button4
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
        promptForSource()



    }else{
        promptForPhotoRoll()
    }

}

1 个答案:

答案 0 :(得分:1)

我发现了问题,不是代码问题,而是电话问题。关闭手机然后备份后,我能够解决问题。