如何避免在应用变换时调整UITextView内容的大小

问题描述 投票:0回答:1

我正在制作一个小笔记应用程序,在其中我在每个单元格内添加了一个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

swift uitextview cgaffinetransform
1个回答
0
投票

问题是您正在增加文本视图的大小,但是字体大小相同。

所以您需要根据缩放倍数更改字体大小。

© www.soinside.com 2019 - 2024. All rights reserved.