在使用系统图片选择器的时候,发现裁剪之后的图片有位置偏移
这个做一个小布丁
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let info = convertFromUIImagePickerControllerInfoKeyDictionary(info)
var image = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] as? UIImage
var crop: CGRect = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.cropRect)] as? CGRect ?? CGRect.zero
crop.origin.y = crop.origin.y + kNavigationBar64//kNavigationBar64就是偏移量
image = ordinaryCrop(imageToCrop: image, cropRect: crop)
}
网友评论