目前越来越多的App都需要顶部标题切换界面效果,并且带有非常炫酷的效果,利用点时间给广大的攻城狮们提供了这样一个框架,集成了当前比较主流的几种效果,网易新闻(字体缩放+颜色渐变),今日头条(颜色填充),喜马拉雅,糗事百科(下标),腾讯视频(蒙版)等。如果喜欢我的文章,可以关注我微博:袁峥Seemygo
Demo简介.png
导航控制器
或者UITabBarController
,需要设置tableView额外滚动区域,详情请看FullChildViewController
网易新闻.gif
@interface YZWYViewController : YZDisplayViewController@end
@implementation YZWYViewController
- (void)viewDidLoad
{[super viewDidLoad];// 添加所有子控制器[self setUpAllViewController];}@end
// 标题渐变// *推荐方式(设置标题渐变)[self setUpTitleGradient:^(YZTitleColorGradientStyle *titleColorGradientStyle, UIColor *__autoreleasing *norColor, UIColor *__autoreleasing *selColor) {}];// 字体缩放// 推荐方式 (设置字体缩放)[self setUpTitleScale:^(CGFloat *titleScale) {// 字体缩放比例*titleScale = 1.3;}];
今日头条标题渐变.gif
@interface YZJRViewController : YZDisplayViewController@end
@implementation YZJRViewController
- (void)viewDidLoad
{[super viewDidLoad];// 添加所有子控制器[self setUpAllViewController];}@end
// 模仿网络延迟,0.2秒后,才知道有多少标题dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{// 移除之前所有子控制器[self.childViewControllers makeObjectsPerformSelector:@selector(removeFromParentViewController)];// 把对应标题保存到控制器中,并且成为子控制器,才能刷新// 添加所有新的子控制器[self setUpAllViewController];// 注意:必须先确定子控制器[self refreshDisplay];});/* 设置标题渐变:标题填充模式 */[self setUpTitleGradient:^(YZTitleColorGradientStyle *titleColorGradientStyle, UIColor *__autoreleasing *norColor, UIColor *__autoreleasing *selColor) {// 标题填充模式*titleColorGradientStyle = YZTitleColorGradientStyleFill;}];
喜马拉雅全屏展示.gif
@interface YZXiMaViewController : YZDisplayViewController@end
@implementation YZXiMaViewController
- (void)viewDidLoad
{[super viewDidLoad];// 添加所有子控制器[self setUpAllViewController];}
@end
// 设置标题字体// 推荐方式[self setUpTitleEffect:^(UIColor *__autoreleasing *titleScrollViewColor, UIColor *__autoreleasing *norColor, UIColor *__autoreleasing *selColor, UIFont *__autoreleasing *titleFont, CGFloat *titleHeight) {// 设置标题字体*titleFont = [UIFont systemFontOfSize:20];}];// 推荐方式(设置下标)[self setUpUnderLineEffect:^(BOOL *isUnderLineDelayScroll, CGFloat *underLineH, UIColor *__autoreleasing *underLineColor) {// 标题填充模式*underLineColor = [UIColor redColor];}];// 设置全屏显示// 如果有导航控制器或者tabBarController,需要设置tableView额外滚动区域,详情请看FullChildViewControllerself.isfullScreen = YES;
@implementation FullChildViewController
- (void)viewDidLoad
{[super viewDidLoad];
// 如果有导航控制器,顶部需要添加额外滚动区域// 添加额外滚动区域 导航条高度 + 标题高度if (self.navigationController) {CGFloat navBarH = self.navigationController.navigationBar.bounds.size.height;// 查看自己标题滚动视图设置的高度,我这里设置为44CGFloat titleScrollViewH = 44;tInset = UIEdgeInsetsMake(navBarH + titleScrollViewH, 0, 0, 0);}// 如果有tabBarController,底部需要添加额外滚动区域
// tInset = UIEdgeInsetsMake(64 + 44, 0, 49, 0);
}
@end
腾讯视频.gif
@interface YZTXViewController : YZDisplayViewController@end
@implementation YZTXViewController
- (void)viewDidLoad
{[super viewDidLoad];// 添加所有子控制器[self setUpAllViewController];}
@end
CGFloat y = self.navigationController?64:0;CGFloat screenW = [UIScreen mainScreen].bounds.size.width;CGFloat screenH = [UIScreen mainScreen].bounds.size.height;// 设置搜索框CGFloat searchH = 44;UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, y, screenW, searchH)];[self.view addSubview:searchBar];// 设置整体内容尺寸(包含标题滚动视图和底部内容滚动视图)[self setUpContentViewFrame:^(UIView *contentView) {CGFloat contentX = 0;CGFloat contentY = CGRectGetMaxY(searchBar.frame);CGFloat contentH = screenH - contentY;contentView.frame = CGRectMake(contentX, contentY, screenW, contentH);}];/****** 标题渐变 ******/// 推荐方式(设置标题颜色渐变) // 默认RGB样式[self setUpTitleGradient:^(YZTitleColorGradientStyle *titleColorGradientStyle, UIColor *__autoreleasing *norColor, UIColor *__autoreleasing *selColor) {*norColor = [UIColor greenColor];*selColor = [UIColor redColor];}];/****** 设置遮盖 ******/// *推荐方式(设置遮盖)[self setUpCoverEffect:^(UIColor **coverColor, CGFloat *coverCornerRadius) {// 设置蒙版颜色*coverColor = [UIColor colorWithWhite:0.7 alpha:0.4];// 设置蒙版圆角半径*coverCornerRadius = 13;}];
点击这下载源代码
作者:袁峥
链接:
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
本文发布于:2024-01-28 11:18:44,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064119307051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |