gpt4 book ai didi

ios - 如何将我的 View 之一与 UIView 类连接?

转载 作者:行者123 更新时间:2023-11-29 04:43:22 25 4
gpt4 key购买 nike

在我的 xib 文件中,我有一些 View 。我有 PainView 类(UIView)。在身份检查器中,我为此 View 设置了PaintView,并制作了@property(强,非原子)IBOutlet PaintView *paintView;

它工作正常,直到我决定更改绘制方法。我从这个 file 复制了代码并粘贴到 PaintView.m 中(与 PaintView.h 相同)。

但只有我写它才有效

[self.view addSubview:[[PaintView alloc] initWithFrame:self.view.bounds]];

但它会在所有其他图层、按钮等之上创建新图层。我需要将此类与现有 View 连接起来。

我尝试了paintView = [[PaintView alloc] initWithFrame:self.view.bounds];但没有成功。

在控制台中它总是显示无效上下文:

<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextGetBaseCTM: invalid context 0x0
<Error>: CGContextConcatCTM: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0

你能帮我一下吗?提前致谢。

最佳答案

您需要实现另一个 init 方法,其初始化与 initWithFrame: 中的初始化相同它的名字是:

- (id)initWithCoder:(NSCoder *)coder 
{
...
}

initWithCoder:是init方法,为 View 调用,从NIB文件加载。

关于ios - 如何将我的 View 之一与 UIView 类连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10030818/

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