我有一个tableview,显示具有imageview和标签的人.当一个人插入桌子时,它可以从触点拉出,图像看起来很好.如果未使用联系人添加某个人,则会从文本字段中提取名称,并为相机显示图像选择器.如果我从后置摄像头拍照没有问题.如果我从前置摄像头拍摄照片,则根据屏幕方向关闭照片.即使在拍摄照片时屏幕没有旋转,它也会根据以下情况关闭:
如果方向为纵向,则图像旋转180度.如果方向是横向左侧,则图像向左旋转90度.如果方向是颠倒的,则图像向右旋转90度.如果方向是正确的,图像就可以了.
这是我提供图像选择器的代码:
func pickImage(){
// create the alert controller, give it three actions: library, camera, cancel
let pickerAlert = UIAlertController(title: "Add Pic?", message: "Would you like to add a picture for this person?", preferredStyle: .Alert)
// create the library action
let libAction = UIAlertAction(title: "Select photo from library", style: .Default) { (alert) -> Void in
// set picker type to the library and present the picker
self.picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(self.picker, animated: true, completion: nil)
}
// if the camera …Run Code Online (Sandbox Code Playgroud)