gpt4 book ai didi

ios - CALayer 的图像不显示

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:46:14 25 4
gpt4 key购买 nike

我正在尝试使用 CALayer 来显示图像,但图像没有显示出来。我已验证“图像”不为零,image.size 正确,并且 layer.contents 是有效的 CABackingStore。

- (void)viewDidLoad
{
[super viewDidLoad];

layer = [[CALayer alloc] init];
[self.view.layer addSublayer:layer];
UIImage *image = [UIImage imageNamed:@"download.jpeg"];
layer.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
layer.position = self.view.center;
layer.contents = (id)image.CGImage;

[layer setNeedsDisplay];
}

这可能是什么问题?

最佳答案

删除 [layer setNeedsDisplay]; 应该可以纠正该行为。

来自docs (强调):

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. The existing content in the layer’s contents property is removed to make way for the new content.

关于ios - CALayer 的图像不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17930454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com