我知道有几个类似的问题,但我仍然没有找到合适的解决方案。我刚刚创建了一个带有自定义视图的测试项目:
@interface CustomView : UIView
//..
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setBackgroundColor:[UIColor redColor]];
}
return self;
}
和视图控制器:
- (void)viewDidLoad
{
[super viewDidLoad];
CustomView *cv = [(CustomView *) [CustomView alloc] initWithFrame:self.view.frame];
[self.view addSubview: cv];
}
在横向模式下,我们可以看到:
如何解决?我知道layoutSubviews
,但1.
在旋转时不会调用它;2.
我如何在这里调整视图的大小?