首先确定两个临界点: 视图的初始高度 悬停的高度。
示例代码(简单控制)
- (void)yl_scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY>=-kNavHeight)
{
offsetY=-kNavHeight;
if (self.headerView.frame.size.height!=kNavHeight)
{
self.headerView.frame = CGRectMake(0, 0, self.headerView.bounds.size.width, kNavHeight);
[UIView animateWithDuration:0.25 animations:^{
self.titleLabel.frame = CGRectMake(35, 20, self.bounds.size.width-35*2, 44);
self.titleLabel.alpha = 1;
}];
}
}else
{
self.headerView.frame = CGRectMake(0, 0, self.headerView.bounds.size.width, -offsetY);
if (self.titleLabel.alpha!=0)
{
[UIView animateWithDuration:0.25 animations:^{
self.titleLabel.frame = CGRectMake(35, 40, self.bounds.size.width-35*2, 44);
self.titleLabel.alpha = 0;
}];
}
}
CGFloat alpha ;
if (self.headerView.frame.size.height>=kWindowWidth/2)
{
alpha = 0;
}else
{
alpha = 1-((self.headerView.frame.size.height-kNavHeight)/(kWindowWidth/2-kNavHeight));
}
if (alpha>=0&α<=1)
{
self.headerEffectView.alpha = alpha;
}
}
最重要的,记得在控制器dealloc时移除监听者
最重要的,记得在控制器dealloc时移除监听者
最重要的,记得在控制器dealloc时移除监听者
或者你有更好的方式移除监听者请告诉我。
照例放Demo,仅供参考,如有问题请留言
Demo地址:
https://github.com/yongliangP/YLSpringHeader 用心良苦请 star
总结
以上所述是小编给大家介绍的iOS实现简单的头部缩放功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对ASPKU网站的支持!










