首页 技术 正文
技术 2022年11月12日
0 收藏 581 点赞 2,433 浏览 2072 个字
要实现点击电池条的时候立即回到页面的顶部的时候注意:

只有当一个主控制器有一个scrollview 并把这个属性设置为yes,其他的scrollview.scrollsToTop = NO 这样才会响应这个事件,原理很简单,如果有2个scrollview,系统根本不知道你需要哪个滚动到最上面 切记!

滑动页面的时候,改变scrollerView 的背景色:
、遵循协议:<UIScrollViewDelegate>、写成私有变量
// 优化页面的拖拽的时候使用
CGFloat _contentOffsetY;
CGFloat _oldContentOffsetY;
CGFloat _newContentOffsetY;、执行方法
#pragma mark—————— 优化页面的拖拽的时候使用(开始)
// 开始拖拽页面
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
_contentOffsetY = scrollView.contentOffset.y;
if (_contentOffsetY <= ) {//确保在向上快拖的时候,底部色值不抖动 scrollView.backgroundColor = K_SET_COLOR_VALUE(K_NAV_BGC);
//NSLog(@"\n\n %s 【_contentOffsetY】= %.2f \n",__FUNCTION__,_contentOffsetY);
}
}
//滚动时候调用该方法(手指离开屏幕后)
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ _newContentOffsetY = scrollView.contentOffset.y; // 滚动
if (_newContentOffsetY > _oldContentOffsetY && _oldContentOffsetY > _contentOffsetY) { // 向上滚动
if (_newContentOffsetY > ) {// 确保,上下抖动的时候,顶部不抖色
scrollView.backgroundColor = K_SET_COLOR_VALUE(K_ROOT_BGC);
} } else if (_newContentOffsetY < _oldContentOffsetY && _oldContentOffsetY < _contentOffsetY) { // 向下滚动
if (_newContentOffsetY < ) {// 确保,上下抖动的时候,底部不抖色 scrollView.backgroundColor = K_SET_COLOR_VALUE(K_NAV_BGC);
//NSLog(@"\n\n %s \n",__FUNCTION__);
} } // 拖拽
if (scrollView.dragging) {
if ((scrollView.contentOffset.y - _contentOffsetY) > 5.0f) { // 向上拖拽 //NSLog(@"\n\n %s 【_newContentOffsetY】 = %.2f \n",__FUNCTION__,_newContentOffsetY);
if (_newContentOffsetY > ) {// 确保,上下抖动的时候,顶部不抖色
scrollView.backgroundColor = K_SET_COLOR_VALUE(K_ROOT_BGC);
} } else if ((_contentOffsetY - scrollView.contentOffset.y) > 5.0f) { // 向下拖拽 if (_newContentOffsetY < ) {// 确保,上下抖动的时候,底部不抖色
scrollView.backgroundColor = K_SET_COLOR_VALUE(K_NAV_BGC);
//NSLog(@"\n\n %s \n",__FUNCTION__);
} }
}
}
// 确实结束减速
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ //NSLog(@"\n\n【_newContentOffsetY】 = %.2f \n",_newContentOffsetY);
if (_newContentOffsetY > ) {//确保在向上快拖的时候,顶部色值不抖动 scrollView.backgroundColor = K_SET_COLOR_VALUE(K_ROOT_BGC);
}
_newContentOffsetY = 0.0f;
}// 完成拖拽(滚动停止时,调用此方法,手指离开屏幕前)
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ _oldContentOffsetY = scrollView.contentOffset.y;}
#pragma mark—————— 优化页面的拖拽的时候使用(结束)
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905