当在Safari中滚动内容时,标题栏将动画为较小版本的自身.实现这一点的最好方法是什么?
目前,我正在改变框架的大小:@H_403_3@
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { // // Table view // CGFloat currentPosition = scrollView.contentOffset.y - CGRectGetHeight(self.tableView.tableHeaderView.frame) + CGRectGetHeight(self.navigationController.navigationBar.frame) + CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]); if ([scrollView isKindOfClass:[HeadlinesHeadlinesTableView class]]) { ScrollDirection scrollDirection; if (self.lastContentOffset > scrollView.contentOffset.y) { scrollDirection = ScrollDirectionDown; } else if (self.lastContentOffset < scrollView.contentOffset.y) { scrollDirection = ScrollDirectionUp; } self.lastContentOffset = scrollView.contentOffset.y; CGRect frame = self.navigationController.navigationBar.frame; CGFloat minimumFrameHeight = 30.0f; CGFloat maximumFrameHeight = 44.0f; CGFloat titleSize = [[self.navigationController.navigationBar.titleTextAttributes objectForKey:NSFontAttributeName] pointSize]; CGFloat minimumTitleHeight = 22.0f; CGFloat maximumTitleHeight = 30.0f; if (currentPosition > 0 && CGRectGetHeight(frame) >= minimumFrameHeight && CGRectGetHeight(frame) <= maximumFrameHeight) { switch (scrollDirection) { case ScrollDirectionUp: frame.size.height--; titleSize--; break; case ScrollDirectionDown: frame.size.height++; titleSize++; break; default: break; } if (CGRectGetHeight(frame) <= minimumFrameHeight) { frame.size.height = minimumFrameHeight; } if (CGRectGetHeight(frame) >= maximumFrameHeight) { frame.size.height = maximumFrameHeight; } if (titleSize <= minimumTitleHeight) { titleSize = minimumTitleHeight; } if (titleSize >= maximumTitleHeight) { titleSize = maximumTitleHeight; } } [self.navigationController.navigationBar setFrame:frame]; [self.navigationController.navigationBar setTitleTextAttributes: @{ NSFontAttributeName : [UIFont fontWithName:@"Canterbury-Regular" size:titleSize] }]; } }
自然而然,这种方式并不顺利,代码很多,更不用说我需要淡出条形按钮项目了.@H_403_3@
提前致谢!@H_403_3@