Joris Mans Joris Mans - 1 year ago 115
iOS Question

View drawRect only called after delay

I made a

subclass that implements custom drawing. Here is the code (please don't mind that this could be done by a
. I stripped the code of all extras just to show the problem)

class TPMSkinnedImageView: UIView {
private var originalImage:UIImage?
private var skinnedImage:UIImage?

@IBInspectable var image: UIImage? {
set {
originalImage = newValue

if(newValue == nil) {
skinnedImage = nil

skinnedImage = originalImage!


get {
return originalImage

override func draw(_ rect: CGRect) {
let context:CGContext! = UIGraphicsGetCurrentContext()
context.translateBy(x: 0, y: rect.height)
context.scaleBy(x: 1, y: -1)
context.draw(skinnedImage!.cgImage!, in: rect)

override var intrinsicContentSize: CGSize {
if(skinnedImage != nil) {
return skinnedImage!.size


I instantiate this view in a viewcontroller nib file and show the viewcontroller modally.

What happens is is that the
method only gets called when the parent view has been on screen for about 20 seconds.

I checked the
and it does not return

This is what the stack looks like once it is called:

enter image description here

Any idea what could be causing this?

Answer Source

Try calling setNeedsDisplay() on your view in your view controller's viewWillAppear()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download