Как избежать изменения размера содержимого UITextView при применении преобразования - PullRequest
0 голосов
/ 07 апреля 2020

Я делаю небольшое приложение для заметок, в котором я добавил textView внутри каждой ячейки, при выборе ячейки он масштабируется до определенного размера, поэтому textView также масштабируется. Все хорошо, за исключением того, что текст внутри textView также масштабируется и выглядит довольно плохо. Кто-нибудь знает, как предотвратить изменение размера текста или как я могу решить эту проблему?

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellReuseIdentifier, for: indexPath) as! collectionViewCell3
    cell.clipsToBounds = false
    cell.layer.cornerRadius = 10
    noteTextView[indexPath.item].frame = CGRect(x: 10, y: 10, width: cell.frame.width - 20, height: cell.frame.height - 20)
    noteTextView[indexPath.item].delegate = self
    noteTextView[indexPath.item].textContainer.maximumNumberOfLines = 10
    noteTextView[indexPath.item].isScrollEnabled = false
    noteTextView[indexPath.item].font = UIFont(name: "Noteworthy-Light", size: 12)
    noteTextView[indexPath.item].text = items[indexPath.item]
    cell.contentView.addSubview(noteTextView[indexPath.item])
    return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    index = indexPath
    notasCollectionView.isScrollEnabled = false
    let cell = notasCollectionView.cellForItem(at: indexPath)
    let desiredPointY = notasCollectionView.contentOffset.y + 350
    let desiredPointX = notasCollectionView.center.x
    let differenceX = desiredPointX - cell!.frame.midX
    let differenceY = desiredPointY - cell!.frame.mid
    let differenceHeight = 354 / (cell?.frame.height)!
    var tt = CGAffineTransform(scaleX: 1.89304813, y: differenceHeight)
    tt = tt.concatenating(CGAffineTransform(translationX: differenceX, y: differenceY))
    UIView.animate(withDuration: 0.2, delay: 0.0, animations: {
        self.notasCollectionView.bringSubviewToFront(cell!)
        cell!.transform = tt
    }, completion: { _ in
        UIView.animate(withDuration: 0.2) {
            cell?.layer.cornerRadius = 0
        }
    })
}

Вот скриншоты:

[! [Скриншот 1] [1]] [1 ] [! [Скриншот 2] [2]] [2]

[1]: https://i.stack.imgur.com/cYURo.png [2]: https://i.stack.imgur.com/LbDND.jpg

1 Ответ

0 голосов
/ 07 апреля 2020

Проблема в том, что вы увеличиваете размер текстового представления, но размер шрифта остается тем же.

Поэтому вам необходимо изменить размер шрифта в соответствии с коэффициентом масштабирования.

...