我有一个iPad应用程序,在其中一个屏幕上,我有一个UIToolbar集为viewController's navigationItem的titleView,还有一个left-和rightBarButtonItem。
当我进入屏幕的景观和旋转设备,titleView保持中心。但是,如果我做相反的操作(输入纵向和旋转设备),titleView就会向右移动。有办法解决这个问题吗?这是我的代码:
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;编辑:
在这两种场景中,self.navigationItem.titleView.frame.size是相同的,变化的是origin.x。
发布于 2013-07-01 09:17:10
如果使用工具栏,请不要将titleView添加为subView。相反,添加项数组。
UIToolbar *titleToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 350, self.navigationController.navigationBar.frame.size.height)];
UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 350, titleToolbar.frame.size.height)];添加条形按钮项目为titleViewBtn,并使边框平原。
titleToolbar.items = @[commentButton, spacer2, downloadButton, spacer3, homeButton, spacer4, **titleViewBtn** , pageDisplayButton, spacer5, searchButton];
titleToolbar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;https://stackoverflow.com/questions/17361227
复制相似问题