I have a custom UIView
subclass inside a UIScrollView
that (among other things) overrides
override var intrinsicContentSize: CGSize {
get {
...
}
}
and (minimal example):
override func draw(_ rect: CGRect) {
print(rect)
UIColor.white.set() // it has a dark background
UIBezierPath(rect: CGRect(x: 100, y: 100, width: 10, height: 10)).stroke()
}
Drawing works fine for “smaller” sizes of the view, but above a certain limit nothing draws anymore.
It renders fine for the rects
(0.0, 0.0, 79.5, 7458.5)
(0.0, 0.0, 228.5, 7458.5)
(0.0, 0.0, 149.0, 7738.0)
(0.0, 0.0, 429.0, 7738.0)
But fails for the rects
(0.0, 0.0, 89.5, 8381.0)
(0.0, 0.0, 257.0, 8381.0)
There is no error message or warning. Nothing that would let me know what fails and why. The UIScrollView
is still scrollable. Its contents are just empty.
This is happening in a simulated 5th generation iPad and the simulated iPad Pro 9.7".
The problem is that draw
is only meant as custom drawing for small views and not huge canvases. However I think this point of failure should be documented somewhere. Making the canvas even larger will result in a ignoring bogus layer size
warning.
To solve this problem one should either consider
UITableView
or a UICollectionView
to load and unload the huge layer bit by bit.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.