0

这是我的代码

CGRect testr = CGRectMake(1, 50, 320, 200);
WeatherViewController *tv = [[WeatherViewController alloc] initWithNibName:@"WeatherViewController" bundle:nil];
UIView *testview = [tv.view initWithFrame:testr];
[self.view addSubview:testview];

无论我在我的 CGRectMake 中输入什么值,视图仍然会位于我的 baseView 的顶部。我究竟做错了什么?

4

1 回答 1

0

发生这种情况的原因是因为您为 testView 提供了无法修改的 viewControllers 视图的矩形,因为这是该 ViewController 的主视图,即使您使用 initWithFrame 也将始终相同:

因此,您所做的方式将无法按您的意愿工作。你将不得不像这样创建一个新的 UIView:

UIView *testView = [[UIView alloc] initWithFrame:frame];

UIViewController 自动创建 UIView 并且不能修改。

于 2013-09-20T12:47:15.443 回答