我有一个 UIView,其子视图在旋转到横向模式后不想完全填充 self.view。我尝试了很多事情,从设置自动调整大小的蒙版到设置旋转后的子视图框架,它们要么不起作用,要么问题变得更糟。这是一个遇到此问题的 UINavigationBar 示例(导航栏未完全填充横向宽度)。编码:
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor blueColor];
myBar =[[UINavigationBar alloc] init];
myBar.frame = CGRectMake (0, 0, self.view.frame.size.width, 44);
UINavigationItem *navItem =[[[UINavigationItem alloc] initWithTitle:@"Title"] autorelease];
UIBarButtonItem *rightButton =[[[UIBarButtonItem alloc] initWithTitle: @"Email" style: UIBarButtonItemStylePlain target: self action:@selector (rightButtonPressed)] autorelease];
navItem.rightBarButtonItem = rightButton;
UIBarButtonItem *leftButton =[[[UIBarButtonItem alloc] initWithTitle: @"About" style: UIBarButtonItemStylePlain target: self action:@selector (leftButtonPressed)] autorelease];
navItem.leftBarButtonItem = leftButton;
myBar.barStyle = UIBarStyleDefault;
myBar.items =[NSArray arrayWithObject:navItem];
[self.view addSubview:myBar];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end