我正在制作一个小笔记应用程序,在其中我在每个单元格内添加了一个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
问题是您正在增加文本视图的大小,但是字体大小相同。
所以您需要根据缩放倍数更改字体大小。