Ios7 在iOS 7中设置UINavigationBar动画(如Safari)

Ios7 在iOS 7中设置UINavigationBar动画(如Safari),ios7,uinavigationbar,uianimation,Ios7,Uinavigationbar,Uianimation,在Safari中滚动内容时,标题栏会显示为其自身的较小版本。实现这一点的最佳方式是什么 目前,我正在更改框架的大小,如下所示: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // // Table view // CGFloat currentPosition = scrollView.contentOffset.y - CGRectGetHeight(self.tableView.tableH

在Safari中滚动内容时,标题栏会显示为其自身的较小版本。实现这一点的最佳方式是什么

目前,我正在更改框架的大小,如下所示:

- (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] }];
    }
}
-(无效)scrollViewDidScroll:(UIScrollView*)scrollView
{
//
//表视图
//
CGFloat currentPosition=scrollView.contentOffset.y-CGRectGetHeight(self.tableView.tableHeaderView.frame)+CGRectGetHeight(self.navigationController.navigationBar.frame)+CGRectGetHeight([[UIApplication sharedApplication]statusBarFrame]);
if([scrollView是类的种类:[HeadlinesHeadlinesTableView类]]){
滚动方向滚动方向;
if(self.lastContentOffset>scrollView.contentOffset.y){
scrollDirection=ScrollDirectionDown;
}else if(self.lastContentOffset0&&CGRectGetHeight(frame)>=minimumFrameHeight&&CGRectGetHeight(frame)查看一下,它已经有淡入淡出支持。

您可以尝试更改导航栏的字体大小,使标题变小。

另一种方法可以替代uibarbuttonitem使用添加到导航栏的uibuttons,然后将其与alpha混为一谈,例如button.alpha=0.0f;诸如此类..希望它能引导您正确的方向:)另请参见: