uiimage добавить к uitextview и изменить размер изображения с помощью Drag, Swift

У меня есть этот код, я читаю изображение из библиотеки, и я хочу изменить размер изображения в 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)
}

0 ответов

Другие вопросы по тегам