UIImagePickerController on iPad with IOS9

前端 未结 7 1158
陌清茗
陌清茗 2021-02-01 03:06

Since iOS 9 and Xcode 7 I am no longer able to implemet a UIImagePickerController on an iPad (both device and simulator). The code below works on the iPad but only prior to iOS

7条回答
  •  半阙折子戏
    2021-02-01 03:44

    Refer the below coding

    @IBAction func photoButton(sender: AnyObject)
    {
       if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
       {
         picker!.sourceType = UIImagePickerControllerSourceType.Camera
         self .presentViewController(picker!, animated: true, completion: nil)
       }
       else
       {
         let alertWarning = UIAlertView(title:"Warning", message: "You don't have camera", delegate:nil, cancelButtonTitle:"OK", otherButtonTitles:"")
         alertWarning.show()
       }
    }
    func openGallary()
    {
       picker!.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
       self.presentViewController(picker!, animated: true, completion: nil)
    }
    
    //PickerView Delegate Methods
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
    {
       picker .dismissViewControllerAnimated(true, completion: nil)
       imageView.image=info[UIImagePickerControllerOriginalImage] as? UIImage
    }
    func imagePickerControllerDidCancel(picker: UIImagePickerController)
    {
       println("picker cancel.")
    }
    

提交回复
热议问题