在UIView中设置viewController视图的大小

时间:2011-12-14 12:50:28

标签: iphone objective-c uiview uiviewcontroller

UIView *view =[[UIView alloc] initWithFrame:CGRect(0,0,300,70)]; //--(View created)
someViewController *someViewControllerObject = [..]; //View Controller Object created.
[view addSubview:[someViewControllerObject.view]];

我想在UIView的对象中调整视图控制器的视图。上面的代码无法正常工作。你能帮我搞清楚吗?

3 个答案:

答案 0 :(得分:1)

最简单的方法是将控制器视图的帧设置为外部视图的边界;

UIView *view =[[UIView alloc] initWithFrame:CGRect(0,0,300,70)]; //--(View created)
someViewController *someViewControllerObject = [..]; //View Controller Object created.
someViewController.view.frame = view.bounds;
[view addSubview:[someViewControllerObject.view]];

答案 1 :(得分:1)

@ david的回答是正确的,可以设置视图控制器视图的初始帧。设置autoResizingMask以获得超级视图更改时所需的行为。

someViewControllerObject.view.frame = view.bounds;
someViewControllerObject.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[view addSubview:someViewControllerObject.view];

答案 2 :(得分:0)

此代码将使其与当前视图的大小相同。

someViewControllerObject.view.frame = view.bounds;
[view addSubview:[someViewControllerObject.view]];