iOS 中的自定义导航栏
我正在开发一个需要自定义 uinavigationbar 的项目。所需的效果是导航控制器中包含的视图堆栈的可视化。
想象一下,对于您向前移动的每个视图,导航栏中会出现一个新按钮,用于您刚刚离开的视图,例如
查看1>>查看2>>查看3
我非常擅长创建自定义的可重复使用的 iOS 组件,但我非常有兴趣了解其他人如何完成此任务。
我现在运行的实例是 UIView 的子视图,在初始化时,我通过为委托类提供的字典数组中详细说明的条目添加 UIButtons 来创建导航栏。
在伪代码中:
@protocol NavDelegate
- (void)UIButtonClicked;
@end
@protocol NavDataSource
- (NSMutableArray *)arrayOfDictionaries;
@end
@interface Navbar : UIView
<NavDelegate,NavDataSource>
{
//create and synthesize delegate and datasource objects
}
@end
@implementation NavBar
- (id)init
{
//override and instantiate necessary objects
}
- (void)layoutSubviews
{
//here I use the number of dictionaries in the delegate returned array to add UIButtons to
//a UIView adding control events for when the button is clicked
}
@end
它有效,但我不禁觉得有一个更优雅的解决方案。
我也有兴趣了解人们是否认为这是应该避免的做法。我始终不愿意“重新发明轮子”,但项目利益相关者认为这是一个很好的 UI 元素。如果舆论的潮流是“不惜一切代价避免”,那么我肯定会把论点还给他们。
预先感谢大家
I am working on a project where there is a requirement for a custom uinavigationbar. The desired effect is a visualisation on the stack of views contained within the navigationcontroller.
Imagine that for each view you move forwards a new button appears in the navigationbar for the view you have just left e.g.
View 1 >> View 2 >> View 3
I am quite comfortable in creating custom resuable iOS components but I am very interested to hear how other people would approach this task.
The instance I have running at the moment is a subview of UIView and on init I create the navigationbar by adding UIButtons for entries detailed in an array of dictionaries provided by the delegate class.
In psudeo code:
@protocol NavDelegate
- (void)UIButtonClicked;
@end
@protocol NavDataSource
- (NSMutableArray *)arrayOfDictionaries;
@end
@interface Navbar : UIView
<NavDelegate,NavDataSource>
{
//create and synthesize delegate and datasource objects
}
@end
@implementation NavBar
- (id)init
{
//override and instantiate necessary objects
}
- (void)layoutSubviews
{
//here I use the number of dictionaries in the delegate returned array to add UIButtons to
//a UIView adding control events for when the button is clicked
}
@end
It works, but I cant help feeling that there is a more elegant solution out there.
I would also be interested to hear if people think that this is a practice that should be avoided. I am reluctant at all times to 'reinvent the wheel' but the project stakeholders think this is a good UI element. If the tide of opinion is 'avoid at all costs' then I will certainly put the argument back to them.
Thanks in advance guys
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信,Apple 在他们自己的有关导航控制器的文档中对这种 UI 不以为然。
听起来你的利益相关者有一种网站面包屑心态……至少在我看来,对于移动应用程序设计来说,这是错误的心态。他们是 UI 人员还是 UX 人员?如果没有,那么……也许他们需要一个。
话虽这么说,他们是客户。 :-)
Apple, I believe, in their own docs about navigation controllers, frown on this sort of UI.
Sounds like your stakeholders have a website breadcrumb mindset... which is the wrong mindset to have, at least in my opinion, for mobile app design. Are they UI or UX people? If not, well... perhaps they need one.
That being said, they are the customer. :-)