顶部View 下拉放大效果

/**

 *  主要思路 

    1.kvo监听expandview的拉伸 

    2.拉伸时候expangviewframe变化的同时设置充满整个屏幕

 */


controller 中

- (void)viewDidLoad {

    [superviewDidLoad];


    UIImageView *imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(0,0, 375*kWidth,180*kHeight)];

    [imageView setImage:[UIImageimageNamed:@"image"]];

    

    

    /**

     *  这里也可以自定义一个view不一定要一个imageview  自定义时候一定要设置imageview属性

     */

   /*

    //关键步骤设置可变化背景view属性

    imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleWidth;

    imageView.clipsToBounds = YES;

    imageView.contentMode = UIViewContentModeScaleAspectFill;

    

    

    [customView addSubview:imageView];

    

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];

    [label setText:@"这是一个自定义头部view"];

    [label setTextColor:[UIColor redColor]];

    [customView addSubview:label];

    

    */

    

    _tableView = [[UITableViewalloc] initWithFrame:CGRectMake(0,0,375*kWidth, 667*kHeight) style:UITableViewStylePlain];

    ;

    _tableView.delegate =self;

    _tableView.dataSource =self;

    [self.viewaddSubview:_tableView];

    _header = [SunExpandHeadernew];

    

    

    /**

     *  这里_tableView只要是scrollview子类就可以

     */

    [_headerexpandWithScrollView:_tableViewexpandView:imageView];

}


 封装的SunExpandHeader

-(void)expandWithScrollView:(UIScrollView *)scrollView expandView:(UIView *)expandView

{

    _expandHeight =CGRectGetHeight(expandView.frame);

    

    _scrollView = scrollView;

    _scrollView.contentInset =UIEdgeInsetsMake(_expandHeight,0, 0,0);

    [_scrollViewinsertSubview:expandView atIndex:0];

    

    [_scrollViewaddObserver:selfforKeyPath:SunExpandContentOffsetoptions:NSKeyValueObservingOptionNewcontext:nil];

    

    _expandView = expandView;

    _expandView.contentMode =UIViewContentModeScaleAspectFill;

    _expandView.clipsToBounds =YES;

}


-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context

{

    if (![keyPathisEqualToString:SunExpandContentOffset]) {

        return;

    }

    [selfscrollViewDidScroll:_scrollView];

}


- (void)scrollViewDidScroll:(UIScrollView*)scrollView

{

    

    CGFloat offsetY = scrollView.contentOffset.y;

    if(offsetY <_expandHeight * -1) {

        CGRect currentFrame =_expandView.frame;

        currentFrame.origin.y = offsetY;

        currentFrame.size.height = -1*offsetY;

        _expandView.frame = currentFrame;

        NSLog(@"1111");

    }

}

- (void)dealloc

{

    if (_scrollView) {

        [_scrollViewremoveObserver:selfforKeyPath:SunExpandContentOffset];

        _scrollView =nil;

    }

    _expandView =nil;

}

http://download.csdn.net/detail/s_c_w_sun/9400463
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值