我想要一個下劃線指示哪個項目被選中。只要物品被點擊,它就會滑動到任何其他物品上。因此,我在自定義UITabBarController
中添加了一個子視圖並設置了動畫。然後我使用hidesBottomBarWhenPushed
按下時隱藏標籤欄。但是,下劃線似乎沒有與定製UITabBarController
結合使用。當interactivePopGesture(如Flipboard)時如何處理UITabBarController的子視圖
如何處理子視圖,使其始終位於頂端,即使使用後手勢?這Flipboard應用程序捕獲是我想要做的。
編輯:
CustomTabBarController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// create underline view
CGRect tabBarFrame = self.tabBar.frame;
CGFloat itemWidth = (CGFloat)CGRectGetWidth(tabBarFrame)/MIN(5, self.tabBar.items.count);
CGFloat originX = (CGFloat)itemWidth * self.selectedIndex;
CGRect underlineFrame = CGRectMake(originX, CGRectGetMaxY(tabBarFrame) - 3.0f, itemWidth, 3.0f);
self.underlineView = [[UIView alloc] initWithFrame:underlineFrame];
self.underlineView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.underlineView];
}
#pragma mark - UITabBarDelegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSUInteger itemIndex = [tabBar.items indexOfObject:item];
CGRect underlineFrame = self.underlineView.frame;
CGFloat originX = (CGFloat)CGRectGetWidth(self.underlineView.frame) * itemIndex;
// underline shifting animation
[UIView animateWithDuration:0.25
animations:^{
self.underlineView.frame = CGRectMake(originX, underlineFrame.origin.y, CGRectGetWidth(underlineFrame), CGRectGetHeight(underlineFrame));
}];
}
CustomTableViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UIViewController *detailViewController = segue.destinationViewController;
detailViewController.hidesBottomBarWhenPushed = YES;
}
hidesBottomBarWhenPushed
隱藏標籤欄,但其子視圖(下劃線視圖)。 如果我自己隱藏並在viewWillAppear
中顯示,則下劃線視圖看起來不像標籤欄頂部。
您應該首先顯示一些代碼,以便我們提供幫助。我從圖中看不到爲什麼你的工作可能不正常 – 2015-03-12 09:21:37