【发布时间】:2013-12-09 12:36:36
【问题描述】:
我想知道为什么你不能改变objective-c中某些物体的XY位置?例如......我有一个带有以下代码的工具栏,但它只有在我将它放在 UIView 中然后设置相同的坐标时才有效......谁能解释为什么?
不起作用:
UIToolbar *commentstoolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 400, 320, 44)];
[self.view addSubview:commentstoolbar];
有效:
UIToolbar *commentstoolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIView *toolbarView = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 320, 44)];
[toolbarView addSubview:commentstoolbar];
[self.view addSubview:toolbarView];
【问题讨论】:
-
这似乎是不寻常的行为......是否有任何其他代码可能会影响这一点?
-
我只用这段代码打开了一个全新的项目,我得到了相同的结果。考虑到没有人为我提供任何可能的解决方案,我必须做错事......
-
假设您在 ViewController 中,您是在 -init -viewDidLoad 还是 -viewDidAppear: 上执行此操作?你还在为这个 View Controller 使用 Interface builder 吗?
标签: objective-c coordinates uitoolbar