2013-03-02 2 views
0

У меня есть UIView, чье подчинение не хочет полностью заполнять self.view после поворота в ландшафтный режим. Я пробовал много вещей, начиная с установки макросов авторезистирования до установки кадров подзаголовков после вращения, либо они не работают, либо проблема становится намного хуже. Вот пример с UINavigationBar, который испытывает эту проблему (navBar не полностью заполняет ширину ландшафта). Код:Пейзаж SubViews не заполняется self.view

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

ответ

1

Просто добавьте одну строку кода в конце кода:

- (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]; 
} 

я удалил autorelease потому что я использовал ARC. Вы можете снова добавить авторекламу. Хорошего друга дня.

+0

Спасибо, что сделал трюк! – s1ris

Смежные вопросы