我有这段代码,我从图书馆读取图像,我希望通过拖动(实时)来调整uitextview
中的图像大小。有谁知道我该怎么做?
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
let attachment = NSTextAttachment()
attachment.image = pickedImage
//calculate new size. (-10 because I want to have a litle space on the right of picture)
let newImageWidth = (txtEditor.bounds.size.width - 10 )
let scale = newImageWidth/(pickedImage?.size.width)!
let newImageHeight = (pickedImage?.size.height)! * scale
//resize this
attachment.bounds = CGRect.init(x: 0, y: 0, width: newImageWidth, height: newImageHeight)
//put your NSTextAttachment into and attributedString
let attString = NSAttributedString(attachment: attachment)
//add this attributed string to the current position.
txtEditor.textStorage.insert(attString, at: txtEditor.selectedRange.location)
}