gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:10:31 24 4
gpt4 key购买 nike

在 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 的字体大小,使标题更小。

关于ios7 - 在 iOS 7 中动画 UINavigationBar(如 Safari),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19363898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com