0

I'm currently learning iOS Programming and I have a (hopefully) simple problem: I wrote a drawing program that works with a customized class of UIView. That gets initialised upon startup in the main view controller in the viewDidLoad method

Image_DrawDraw *drawing = [[Image_DrawDraw alloc] initWithFrame:self.view.bounds];
[self.view addSubview:drawing];

I now want to change my program into a bit more sophisticated. I made a xib File containing some buttons, status bar and and image view. I still want to be able to draw in this new view, precisely over the image view, but not over the status bar or the buttons. But I have problems in initializing my Image_DrawDraw class it just overrides the whole xib and I'm back to my black screen where I can draw. Thank you for your help!

4

1 回答 1

0

views当您将子视图添加到视图层次结构时,它成为超级视图数组属性中的最后一项。视图的分层顺序是基于views数组的,最下面的视图是位于的项目,[views objectAtIndex:0]最上面的视图是位于的项目[views lastObject]。通过在 Xib 上安排所有其他视图,然后在 Xib 加载后在代码中添加 Image_DrawDraw 视图,您将其设置为最上面的视图,从而遮挡您的按钮。

您可以直接将其放在 Xib 中,而不是将其添加到代码中。

将自定义视图添加到您的 xib。将其放置在您现有的 xib 图像视图上方和按钮下方。将视图的自定义类设置为 Image_DrawDraw。

现在您将不需要以下任何代码行:

Image_DrawDraw *drawing = [[Image_DrawDraw alloc] initWithFrame:self.view.bounds];
[self.view addSubview:drawing];

要在代码中引用您的 Image_DrawDraw xib 视图,您应该在 viewController 中为其创建一个 IBOutlet 属性,并通过在 Xib@interface文件中按住 CTRL 并拖出一条线将 Xib 视图连接到 IBOutlet。

于 2013-01-27T04:31:39.460 回答