下拉放大, 上推渐变

2016-08-20 13_11_15.gif
属性
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIView *backGroundView;
@property (nonatomic, strong)UIImageView *imageView;
@property (nonatomic, strong)UIImageView *barImageView;```
######要在导航栏上显示图片

[self.navigationController.navigationBar setBackgroundImage:[UIImage alloc] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];

######创建TableView
  • (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -64, self.view.bounds.size.width, self.view.bounds.size.height + 64)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    _tableView.tableHeaderView = [self creatTableViewHeaderView];
    self.barImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -20, WIDTH, 64)];
    _barImageView.image = [UIImage imageNamed:@"tts-navbar"];
    [self.navigationController.navigationBar addSubview:_barImageView];
    self.navigationItem.title = @"导航栏";
    }
  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
    }
  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = [NSString stringWithFormat:@"cell = %ld", (long)indexPath.row];
    return cell;
    }
######将图片放在头视图上
  • (UIView *)creatTableViewHeaderView {
    self.backGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
    self.imageView = [[UIImageView alloc] initWithFrame:self.backGroundView.bounds];
    _imageView.image = [UIImage imageNamed:@"1.jpg"];
    [self.backGroundView addSubview:_imageView];
    return _backGroundView;
    }
#####上推渐变, 下拉放大的设置
  • (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // 上推渐变
    CGFloat offset_Y = scrollView.contentOffset.y;
    CGFloat alpha = (offset_Y + 64) / 200.0f;
    self.barImageView.alpha = alpha;
    // 下拉放大
    if (offset_Y < -64) {
    CGFloat add_height = -(offset_Y + 64);
    CGFloat scale = (200 + add_height) / 200.0f;
    self.imageView.frame = CGRectMake(-(WIDTH * scale - WIDTH) / 2.0f, -add_height, WIDTH * scale, 200 + add_height);
    NSLog(@"%f", scale);
    }
    }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,466评论 4 61
  • 转载自:https://github.com/Tim9Liu9/TimLiu-iOS 目录 UI下拉刷新模糊效果A...
    袁俊亮技术博客阅读 12,131评论 9 105
  • 国内英语教材已经有很多版本了,外研版、人教版、牛津版,有的学校还有自己的校本教材,也算五花八门了,可是,没有对比就...
    Sunnywinter777阅读 1,004评论 5 3
  • China’s Weibo eclipses rival Twitter’s market capitalizat...
    huuila阅读 328评论 0 0
  • 初五迎财神,从范蠡想到了《史记》的《货殖列传》,之前买的是中华书局的繁体非注解版,没法看,束之高阁,还是找来度娘。...
    掌门_艾老师阅读 375评论 0 1

友情链接更多精彩内容