在我的iOS应用中,我想将图片上传为个人资料照片。因此,我需要像Icon这样的内容来上传图像,然后需要弹出窗口或这样的用户界面来通过相机制作照片或从设备上的相册上传照片。它应该像Facebook一样。
我用XCode 6和Swift创建了我的应用程序。有没有想法,解决方案或其他信息?
THX!
答案 0 :(得分:2)
我已通过以下代码解决了我的问题:
func takePhoto(sender: AnyObject) {
if (UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){
var picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = UIImagePickerControllerSourceType.Camera
var mediaTypes: Array<AnyObject> = [kUTTypeImage]
picker.mediaTypes = mediaTypes
picker.allowsEditing = true
self.presentViewController(picker, animated: true, completion: nil)
}
else{
NSLog("No Camera.")
}
}
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
let selectedImage : UIImage = image
}