Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't use <code>-drawLayer:inContext:</code>. That method is for drawing into a CG context which will then become the layer's contents, using Core Graphics or UIKit methods. You don't want to change the layer's contents at all -- you want to set it to be your image, once, and then never touch it again.</p> <p>Your image is appearing and disappearing, because sometimes the layer displays the image, and other times the layer displays what you drew into the context in <code>-drawLayer:inContext:</code> -- namely, nothing.</p> <p>(Also: in order for <code>-drawLayer:inContext:</code> to be called, you must be calling <code>[layer setNeedsDisplay]</code>, or you have the layer's <code>needsDisplayOnBoundsChange</code> turned on, or something similar. Don't do any of that.)</p> <p>Instead, try using the <code>CALayer</code> layout machinery. For instance, in your layer's delegate:</p> <pre><code>- (void)layoutSublayersOfLayer:(CALayer *)layer { float alpha = layer.position.y / layer.superlayer.bounds.size.height; UIColor *reddish = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:alpha]; CGColorRef cgReddish = reddish.CGColor; layer.backgroundColor = cgReddish; } </code></pre> <p>This will get called as part of the display process, anytime the layer or any of its superlayers have had their <code>-setNeedsLayout</code> method called. Often this happens automatically, but depending on exactly what causes the layer to move, you may need to do it manually. Try it and see.</p> <p>(Alternatively: Since you already have code that changes the layer's position, why not change the layer's background color at the same time?)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload