首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UINavigationItem titleView定位问题

UINavigationItem titleView定位问题
EN

Stack Overflow用户
提问于 2013-06-28 09:15:12
回答 1查看 1.7K关注 0票数 4

我有一个iPad应用程序,在其中一个屏幕上,我有一个UIToolbar集为viewController's navigationItemtitleView,还有一个left-rightBarButtonItem

当我进入屏幕的景观和旋转设备,titleView保持中心。但是,如果我做相反的操作(输入纵向和旋转设备),titleView就会向右移动。有办法解决这个问题吗?这是我的代码:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

发布于 2013-07-01 09:17:10

如果使用工具栏,请不要将titleView添加为subView。相反,添加项数组。

代码语言:javascript
复制
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,并使边框平原。

代码语言:javascript
复制
titleToolbar.items = @[commentButton, spacer2, downloadButton, spacer3, homeButton, spacer4, **titleViewBtn** , pageDisplayButton, spacer5, searchButton];
titleToolbar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17361227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档