У меня есть проблема с использованием UITextKit exclusionPaths: когда я поместить изображение внутри TextView, что я редактирую, первое все выглядит отлично:UITextKit и exclusionPaths: ненадежный отступ при редактировании
Но когда «Готово» -Кнопка сливают, это будет выглядеть как это, идент неправильно:
Это класс для хранения информации для изображения
class ImageClass {
var image: UIImage!
var imageView: UIImageView
var imageName: String!
var active:Bool
var exclusivePath: UIBezierPath!
init(image: UIImage!, imageName: String!) {
self.image = image
imageView = UIImageView(image: image!)
self.imageName = imageName
self.active = false
self.exclusivePath = nil
}
}
Пользователь выбирает изображение в UICollectionView, которое вызывает делегат, когда выбрано изображение. (ImageViewObjects является массивом, где я могу поставить объекты ImageCLASS, так что я могу использовать Mutiple изображения)
// MARK: - SelectImageDelegate
func selectedImage(name:String) {
let image = UIImage(named: name)
let imageViewObject = ImageClass(image: image, imageName: name)
self.imageViewObjects.append(imageViewObject)
imageViewObject.imageView.frame = CGRectMake(4, 7, width!, height!)
// define the exlusionPaths
let bezierPath = self.exclusionPathForImageView(imageViewObject.imageView)
imageViewObject.exclusivePath = bezierPath
self.updateExclusionPaths()
self.textView.addSubview(imageViewObject.imageView)
}
// set UIBezierPath for the UIImageView
func exclusionPathForImageView(imageView: UIImageView) -> UIBezierPath {
let bezierPath = UIBezierPath(rect:
CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,
imageView.frame.width, imageView.frame.height))
return bezierPath
}
func updateExclusionPaths() {
textView.textContainer.exclusionPaths = []
for imageViewObject in self.imageViewObjects {
textView.textContainer.exclusionPaths.append(imageViewObject.exclusivePath)
}
}
Контекст bezierPath нормально.
Когда «Готово» сливают, я остановить редактирование
let doneBarButton = UIBarButtonItem(title: "Done", style: .Done, target: view, action: Selector("endEditing:"))
В textViewDidEndEditing() теперь я ничего не делаю.
Я также пробовал его с UIButton для изображения. Аналогичный результат.
Любой отзыв для решения? PLZ помочь мне !!!!