小编use*_*054的帖子

如何将UIView添加到CALayer

我正在尝试添加一个自定义UIView,CALayer但它没有被渲染.

我没有将自定义视图添加到另一个视图.相反,我正在尝试将其直接添加到CALayer.

如果我确实将自定义视图添加到另一个视图(即[self.view addSubview:customView]),它可以工作,但由于某种原因,在触摸屏幕的那一刻开始导致崩溃.

所以基本上

[self.view addSubview:customView];
[layer addSublayer:customView.layer]; //Causes crashes the minute the screen is touched
Run Code Online (Sandbox Code Playgroud)

以下是代码:

CustomView *customView = [[CustomView alloc] initWithFrame:frame];

//I'm not adding the custom view to another view
//Instead I'm trying to add it to a CALayer

CALayer *layer = [CALayer layer];
[Layer setFrame:frame2];
[layer addSublayer: customView.layer];
Run Code Online (Sandbox Code Playgroud)

PS我目前的解决方法是将UIView转换为UIImage并将其添加到CALayer.

Belo是自定义的UIView代码:

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
    self.font = [UIFont fontWithName:ARCVIEW_DEFAULT_FONT_NAME size:ARCVIEW_DEFAULT_FONT_SIZE];
    self.text = @"Curva …
Run Code Online (Sandbox Code Playgroud)

calayer uiview ios

1
推荐指数
1
解决办法
2127
查看次数

标签 统计

calayer ×1

ios ×1

uiview ×1