更新时间:2022-12-29 23:07:33
NIB/XIB文件通常包含一个UIViewController
来处理所有这些问题.在这种情况下,由于它们不是视图控制器(在NIB/XIB中),因此您需要接管其后加载任务.
Often a NIB/XIB file contains a UIViewController
that takes care of all of this. In this case, since their is no view controller (in the NIB/XIB) you need to take over its post-load duties.
直接调用layoutSubviews
或通过setNeedsLayout
或layoutIfNeeded
间接调用layoutSubviews
对您没有多大好处,因为默认实现不执行任何操作.
Calling layoutSubviews
directly, or indirectly via setNeedsLayout
or layoutIfNeeded
won't do you much good because the default implementation does nothing.
假设您希望输入视图填充self.view的边界,请执行以下操作:
Assuming you want input view to fill the bounds of self.view you do the following:
InputView *inputView = (InputView*)[nibObjects objectAtIndex:0];
[self.view addSubview:inputView];
inputView.frame = self.view.bounds;
[inputView show];
必须正确设置所有子视图的调整尺寸蒙版 ,显然,如果您不想填充整个边界,则可能需要调整框架.
All the resize masks of the sub-views must be correctly set for this to work and, obviously, if you don't want to fill the full bounds you may want to adjust the frame.