在 ios7 上,许多应用程序(Apple Messages、Facebook Messenger、Calendar)的视图出现在 UINavigationBar 下,通常带有看似标准的动画。因为它看起来很标准并且看起来很像 UIToolBar,所以我一直在寻找实现它的标准方法,但找不到任何东西。
有没有更好的方法将 UIToolBar 添加到 UINavigationBar?
您应该遵循这个简单的方法。
-
Add a UIToolBar
像这样。
UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil];
NSArray *items = [NSArray arrayWithObjects:item1, flexiableItem, item2, nil];
self.toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, -44, self.view.frame.size.width, 44)];
[self.toolBar setItems:items];
self.toolBar.tintColor = [UIColor whiteColor];
self.toolBar.barTintColor = [UIColor colorWithRed:0.6 green:0.1 blue:0.2 alpha:1];
[self.contentView addSubview:self.toolBar];
-
在顶部导航项上添加菜单按钮
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleMenu:)];
-
现在实施toggleMenu
功能。添加一个BOOL
变量来跟踪运动。
if(!moved) {
[UIView animateWithDuration:0.5 animations:^{
self.toolBar.alpha = 1;
self.toolBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
}];
moved = YES;
}else {
[UIView animateWithDuration:0.5 animations:^{
self.toolBar.alpha = 1;
self.toolBar.frame = CGRectMake(0, -44, self.view.frame.size.width, 44);
}];
moved = NO;
}
这是附件video为了这。
希望有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)