UIView *view =[[UIView alloc] initWithFrame:CGRect(0,0,300,70)]; //--(View created)
someViewController *someViewControllerObject = [..]; //View Controller Object created.
[view addSubview:[someViewControllerObject.view]];
我想在UIView的对象中调整视图控制器的视图。上面的代码无法正常工作。你能帮我搞清楚吗?
答案 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]];