2 xcode resize frame subview superview
My window adds a subview (my root ViewController's view).
Such subview is superview of several other subviews.
I have just finished an app, and now I want to add an ad.
Here's some code:
[window addSubview:viewController.view];
viewController.view.frame=CGRectMake(0,0,320,480-48);
viewController.clipToBounds=YES;
Ad *ad=[Ad alloc] initWithFrame:CGRectMake(0,480-48,320,48)];
Run Code Online (Sandbox Code Playgroud)
上面的viewController有几个子视图,但它们不会调整大小.上面的viewController.view最初是320,480,完全填充了子视图,直到底部的最后一个像素.在我将其高度从480更改为460后,子视图不会调整大小,因此在视图的底部(广告所在的位置),某些子视图不可见.
我如何调整子视图以适应父视图(viewController.view),当后者的高度减少20px时?(我知道他们会变形一点)
您需要为子视图设置自动调整大小:
ad.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅UIView文档.
| 归档时间: |
|
| 查看次数: |
16496 次 |
| 最近记录: |