Ios 未填充self.view的横向子视图

Ios 未填充self.view的横向子视图,ios,objective-c,orientation,Ios,Objective C,Orientation,我有一个UIView,其子视图在旋转到横向模式后不希望完全填充self.view。我尝试过很多方法,从设置自动调整大小遮罩到设置旋转后的子视图帧,它们要么不起作用,要么问题变得更糟。下面是一个UINavigationBar遇到此问题的示例(NAVIGATIONBAR不能完全填充横向宽度)。守则: - (void)loadView { self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame

我有一个UIView,其子视图在旋转到横向模式后不希望完全填充self.view。我尝试过很多方法,从设置自动调整大小遮罩到设置旋转后的子视图帧,它们要么不起作用,要么问题变得更糟。下面是一个UINavigationBar遇到此问题的示例(NAVIGATIONBAR不能完全填充横向宽度)。守则:

- (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

只需在代码末尾添加一行代码:

- (void)loadView
{
    self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    self.view.backgroundColor = [UIColor blueColor];
    UINavigationBar *myBar;
    myBar =[[UINavigationBar alloc] init];
    myBar.frame = CGRectMake (0, 0, self.view.frame.size.width, 44);
    UINavigationItem *navItem =[[UINavigationItem alloc] initWithTitle:@"Title"];
    UIBarButtonItem *rightButton =[[UIBarButtonItem alloc] initWithTitle: @"Email" style: UIBarButtonItemStylePlain target: self action:@selector (rightButtonPressed)];
    navItem.rightBarButtonItem = rightButton;
    UIBarButtonItem *leftButton =[[UIBarButtonItem alloc] initWithTitle: @"About" style:     UIBarButtonItemStylePlain target: self action:@selector (leftButtonPressed)];
    navItem.leftBarButtonItem = leftButton;
    myBar.barStyle = UIBarStyleDefault;
    myBar.items =[NSArray arrayWithObject:navItem];
    [self.view addSubview:myBar];
    [myBar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
}
我删除了自动释放,因为我使用了ARC。您可以再次添加自动释放。祝你有个好朋友