ios7 – 在iOS 7中动画化UINavigationBar(如Safari)

前端之家收集整理的这篇文章主要介绍了ios7 – 在iOS 7中动画化UINavigationBar(如Safari)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当在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] }];
    }
}

自然而然,这种方式并不顺利,代码很多,更不用说我需要淡出条形按钮项目了.

提前致谢!

解决方法

看看 AMScrollingNavbar,它已经有褪色的支持. 您可以尝试更改NavigationBar的字体大小,使标题更小.
原文链接:https://www.f2er.com/iOS/335986.html

猜你在找的iOS相关文章