I have an iPad app, and on one of the screens I set UIToolbar as titleView viewController navigationItem . I also have left- and rightBarButtonItem .
When I enter the screen in landscape orientation and rotate the device, the titleView remains centered. However, if I do the opposite (enter a portrait and rotate the device), the titleView to the right. Is there any way to fix this? Here is my code:
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 350, self.navigationController.navigationBar.frame.size.height)]; UIToolbar *titleToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 350, self.navigationController.navigationBar.frame.size.height)]; titleToolbar.items = @[commentButton, spacer2, downloadButton, spacer3, homeButton, spacer4, pageDisplayButton, spacer5, searchButton]; titleToolbar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; [titleView addSubview:titleToolbar]; self.navigationItem.titleView = titleView;
Edit:
In both scripts, self.navigationItem.titleView.frame.size the same as changing origin.x
source share