滑动代理scrollViewDidScroll

//结合前面写的在NavigationItem.titleView添加视图,加入滑动代理,就可以在滑动TableView的时候,实现NavigationItem.titleView的变大缩小


#pragma mark - 滑动代理

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGFloat offsetY = scrollView.contentOffset.y + _newsTableView.contentInset.top;//注意

/**

*  1 - offsetY/num1 = 0.45;

0.45 为最终缩小倍率

offsetY 为纵偏移量

num1=300 为要计算的值

150/165  就是滑动多少距离后,完成缩放

*/

if (offsetY < 0 && offsetY >= -150) {

_topImageView.transform = CGAffineTransformMakeScale(1 + offsetY/(-300), 1 + offsetY/(-300));

//        _topImageView.layer.anchorPoint = CGPointMake(0.5, offsetY/600. + 0.5);

//        NSLog(@"%lf - %lf", offsetY, 1 + offsetY/(-300));

}

else if (offsetY >= 0 && offsetY <= 165) {

_topImageView.transform = CGAffineTransformMakeScale(1 - offsetY/300, 1 - offsetY/300);

//        _topImageView.layer.anchorPoint = CGPointMake(0.5, 0.5 + offsetY/600.);

}

else if (offsetY > 165) {

_topImageView.transform = CGAffineTransformMakeScale(0.45, 0.45);

//        _topImageView.layer.anchorPoint = CGPointMake(0.5, 1);

}

else if (offsetY < -150) {

_topImageView.transform = CGAffineTransformMakeScale(1.5, 1.5);

//        _topImageView.layer.anchorPoint = CGPointMake(0.5, 0.5);

}

CGRect frame = _topImageView.frame;

frame.origin.y = 5;

_topImageView.frame = frame;

}

你可能感兴趣的:(滑动代理scrollViewDidScroll)