我们如何强制UII
ImagePickerController裁剪正方形图像?
var imagePickerController: UIImagePickerController = UIImagePickerController(); imagePickerController.allowsEditing = true; imagePickerController.delegate = self; imagePickerController.sourceType = sourceType; func imagePickerController(picker: UIImagePickerController,didFinishPickingImage image: UIImage!,editingInfo: [NSObject : AnyObject]!) { profilePictureSelected = true; profilePictureImageView.image = image; picker.dismissViewControllerAnimated(true,completion: nil); }
解决方法
您正在正确地执行,直到您收到委托回调,在您需要指定它是您要使用的编辑图像的回调中.请注意,我在这里使用不同的委托方法.
func imagePickerController(picker: UIImagePickerController,didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) { if let chosenImage = info[UIImagePickerControllerEditedImage] as? UIImage { profilePictureSelected = true; profilePictureImageView.image = chosenImage; } picker.dismissViewControllerAnimated(true,completion: nil); }