Swift,相机图像不 return
Swift, Camera image doesn't return
请原谅我的初学者问题。我加载相机并拍照,但似乎从未调用覆盖函数 imagePickerController
,所以我永远无法将照片设置到 imageView,代码如下。任何想法?谢谢
@IBAction func takePhotoClick(_ sender: AnyObject) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
}
var imagePicker: UIImagePickerController!
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
imagePicker.dismiss(animated: true, completion: nil)
photoImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
You need to ask the use permission before access the user private data like contact number, photos , location , calendar , etc. in iOS 10 Apple is extending the scope of privacy control. You have to declare in Info.plist file access of any private data.
Which framework have privacy key in Info.plist :
Calendar , Contact , Reminder , Photo , Bluetooth Sharing , Microphone , Camera , Location , Heath , HomeKit , Media Library , Motion , CallKit , Speech Recognition , SiriKit , TV Provider.
有关详细信息,请参阅 this
检查一次您是否在 plist 中添加了以下信息
然后像
一样调用委托方法
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
photoImageView.image = image
}
picker.dismiss(animated: true, completion: nil);
}
请原谅我的初学者问题。我加载相机并拍照,但似乎从未调用覆盖函数 imagePickerController
,所以我永远无法将照片设置到 imageView,代码如下。任何想法?谢谢
@IBAction func takePhotoClick(_ sender: AnyObject) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
}
var imagePicker: UIImagePickerController!
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
imagePicker.dismiss(animated: true, completion: nil)
photoImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
You need to ask the use permission before access the user private data like contact number, photos , location , calendar , etc. in iOS 10 Apple is extending the scope of privacy control. You have to declare in Info.plist file access of any private data.
Which framework have privacy key in Info.plist :
Calendar , Contact , Reminder , Photo , Bluetooth Sharing , Microphone , Camera , Location , Heath , HomeKit , Media Library , Motion , CallKit , Speech Recognition , SiriKit , TV Provider.
有关详细信息,请参阅 this
检查一次您是否在 plist 中添加了以下信息
然后像
一样调用委托方法 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
photoImageView.image = image
}
picker.dismiss(animated: true, completion: nil);
}