ios - CALayer 的图像未显示
<p><p>我正在尝试使用 CALayer 显示图像,但图像未显示。我已经验证了 'image' 不是 nil,image.size 是正确的,并且 layer.contents 是一个有效的 CABackingStore。</p>
<pre><code>- (void)viewDidLoad
{
;
layer = [ init];
;
UIImage *image = ;
layer.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
layer.position = self.view.center;
layer.contents = (id)image.CGImage;
;
}
</code></pre>
<p>这可能是什么问题?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>删除 <code>;</code> 应该会纠正这种行为。</p>
<p>来自 <a href="https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html#//apple_ref/occ/instm/CALayer/setNeedsDisplay" rel="noreferrer noopener nofollow">docs</a> (强调):</p>
<blockquote>
<p>Calling this method causes the layer to recache its content. This results in the layer potentially calling either the displayLayer: or drawLayer:inContext: method of its delegate. <strong>The existing content in the layer’s contents property is removed to make way for the new content.</strong></p>
</blockquote></p>
<p style="font-size: 20px;">关于ios - CALayer 的图像未显示,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/17930454/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/17930454/
</a>
</p>
页:
[1]