iOS: Custom UISegmentedControl no se ajusta cuando se cambia la orientación.

Mi vista de retrato original es así

introduzca la descripción de la imagen aquí

Cuando cambio la orientación y gire el simulador hacia la izquierda o hacia la derecha, aparece

introduzca la descripción de la imagen aquí

Cuando hago clic en cualquier pestaña que no sea "Perfil", la barra de tabs se ajusta de la manera que deseo.

Estoy usando UISegmentedControl personalizado en el control de navigation. Cómo ajustar las vistas para barras de tabs inmediatamente cuando se cambia la rotation de la pantalla.

Usar Xcode 4.6 y la implementación es para todas las versiones de iOS.

Aquí está mi código

- (void)viewDidLoad { [super viewDidLoad]; //Tapped outside to hide keyboard UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; [self.view addGestureRecognizer:tapped]; tapped.cancelsTouchesInView = NO; [self.navigationItem setHidesBackButton:YES animated:YES]; profileSegmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects: @"Profile", @"List", @"Scan", @"Collaborate", @"Logout", nil]]; [profileSegmentControl addTarget:self action:@selector(profileButton) forControlEvents:UIControlEventValueChanged]; if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationPortrait) { UIFont *font = [UIFont boldSystemFontOfSize:10.5f]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont]; [profileSegmentControl setTitleTextAttributes:attributes forState:UIControlStateNormal]; profileSegmentControl.frame = CGRectMake(0, 0, 318, 30); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) { profileSegmentControl.frame = CGRectMake(0, 0, 470, 30); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) { profileSegmentControl.frame = CGRectMake(0, 0, 470, 30); } [self.view setNeedsLayout]; } else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationPortrait) { profileSegmentControl.frame = CGRectMake(0, 0, 758, 40); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) { profileSegmentControl.frame = CGRectMake(0, 0, 994, 40); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) { profileSegmentControl.frame = CGRectMake(0, 0, 994, 40); } [self.view setNeedsLayout]; } profileSegmentControl.segmentedControlStyle = UISegmentedControlStyleBar; profileSegmentControl.momentary = YES; //[profileSegmentControl sizeToFit]; UINavigationBar *bar = [self.navigationController navigationBar]; [bar setTintColor:[UIColor blackColor]]; UIBarButtonItem *profileSegmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:profileSegmentControl]; self.navigationItem.rightBarButtonItem = profileSegmentBarItem; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return [self.presentingViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; } -(BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } 

debe ajustar uisegmentcontrol en el cambio de delegado de orientación configurando su marco de acuerdo con sus requerimientos

Implementado cortando el pegado del siguiente código en el método (NSUInteger) supportInterfaceOrientations

 if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationPortrait) { UIFont *font = [UIFont boldSystemFontOfSize:10.5f]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont]; [profileSegmentControl setTitleTextAttributes:attributes forState:UIControlStateNormal]; profileSegmentControl.frame = CGRectMake(0, 0, 318, 30); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) { profileSegmentControl.frame = CGRectMake(0, 0, 470, 30); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) { profileSegmentControl.frame = CGRectMake(0, 0, 470, 30); } [self.view setNeedsLayout]; } else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationPortrait) { profileSegmentControl.frame = CGRectMake(0, 0, 758, 40); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) { profileSegmentControl.frame = CGRectMake(0, 0, 994, 40); } else if([UIApplication shanetworkingApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) { profileSegmentControl.frame = CGRectMake(0, 0, 994, 40); } [self.view setNeedsLayout]; }