监听webview的滑动
2015-12-01 19:09
627 查看
在如今html5越来越横行的年代,app里面webview的交互显得越发重要起来。。。
有时候你会碰到内置控件与webview共存在一个页面的情况。如下图:
这个时候令人蛋疼的事儿就来啦。。 你如果不加控制。让webview只在下半部分显示。在6和6p上还好,但是在4s上就不能忍啦。
你必须控制上面轮播的与webview同时移动到顶端。然后webview自主滑动。。这才是人家产品要的效果!!!
要想实现上述效果。监听到webview的滑动是前提!。网上搜了半天。没有什么有效地答案。
苦思冥想了半天。。终于解决啦
啥都不说啦。上代码!!!!:::::
监听到webview的滑动: _webView.scrollView.delegate = self;
实现随动效果:
static float tempY = 0;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
tempY += scrollView.contentOffset.y;
if (tempY >= 150) {
tempY = 150;
}
if (tempY <=0) {
tempY =0 ;
}
NSLog(@"tempY = %f", tempY);
if (tempY < 150&&tempY>0) {//根据当前temp来判断轮播图的状态
scrollView.contentOffset = CGPointZero;
//滑动的距离
CGFloat scrolly = tempY;
//向上滑动的距离越大。透明度越小
CGFloat h = 150 - scrolly;//头部高度减去移动距离
// CGFloat alpha = h/150.0;
// NSLog(@"y=%f, alpha=%f", scrolly,alpha);
// sdCycleView.alpha = alpha>1?1.0:alpha;
// NSLog(@"h=========&********%f",h);
sdCycleView.frame = CGRectMake(0, 0, Width, h);
_webView.frame = CGRectMake(0, sdCycleView.bottom, Width, Height-113);
}else if(tempY == 0){//轮播图显现之后重置
sdCycleView.frame = CGRectMake(0, 0, Width, 150 - scrollView.contentOffset.y);
_webView.frame = CGRectMake(0, sdCycleView.bottom, Width, Height-113);
}else {//轮播图隐藏之后webview正常滑动
sdCycleView.frame = CGRectMake(0, 0, Width, 0);
_webView.frame = CGRectMake(0, 0, Width, Height-113);
}
}
有同样需求的同学可以参考一下。!!
有时候你会碰到内置控件与webview共存在一个页面的情况。如下图:
这个时候令人蛋疼的事儿就来啦。。 你如果不加控制。让webview只在下半部分显示。在6和6p上还好,但是在4s上就不能忍啦。
你必须控制上面轮播的与webview同时移动到顶端。然后webview自主滑动。。这才是人家产品要的效果!!!
要想实现上述效果。监听到webview的滑动是前提!。网上搜了半天。没有什么有效地答案。
苦思冥想了半天。。终于解决啦
啥都不说啦。上代码!!!!:::::
监听到webview的滑动: _webView.scrollView.delegate = self;
实现随动效果:
static float tempY = 0;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
tempY += scrollView.contentOffset.y;
if (tempY >= 150) {
tempY = 150;
}
if (tempY <=0) {
tempY =0 ;
}
NSLog(@"tempY = %f", tempY);
if (tempY < 150&&tempY>0) {//根据当前temp来判断轮播图的状态
scrollView.contentOffset = CGPointZero;
//滑动的距离
CGFloat scrolly = tempY;
//向上滑动的距离越大。透明度越小
CGFloat h = 150 - scrolly;//头部高度减去移动距离
// CGFloat alpha = h/150.0;
// NSLog(@"y=%f, alpha=%f", scrolly,alpha);
// sdCycleView.alpha = alpha>1?1.0:alpha;
// NSLog(@"h=========&********%f",h);
sdCycleView.frame = CGRectMake(0, 0, Width, h);
_webView.frame = CGRectMake(0, sdCycleView.bottom, Width, Height-113);
}else if(tempY == 0){//轮播图显现之后重置
sdCycleView.frame = CGRectMake(0, 0, Width, 150 - scrollView.contentOffset.y);
_webView.frame = CGRectMake(0, sdCycleView.bottom, Width, Height-113);
}else {//轮播图隐藏之后webview正常滑动
sdCycleView.frame = CGRectMake(0, 0, Width, 0);
_webView.frame = CGRectMake(0, 0, Width, Height-113);
}
}
有同样需求的同学可以参考一下。!!
相关文章推荐
- Objective-C NSArray & NSMutableArray
- iOS 7: 使用Base64编解码NSData和NSString对象
- Android开发App架构MVP模式
- iOS_ 用户引导界面代码
- object-c之自定义UITableViewCell
- object-c之自定义UITableViewCell
- 苹果开发 手动内存管理MRC
- Android 虚线分割线
- 解决一些android studio 中的编码问题
- Android中几种常用的定时器和延时方法
- android 同时实现微信分享和微信登录功能
- iOS9 通讯录(无界面的和有界面的)
- Android的按钮单击事件及监听器的实现方式
- ubuntu下Qt之android环境配置以及一些常见问题解决
- iOS社会化分享
- Checklists学习日志之@UIAPPLICATIONMAIN
- android坐标
- Happy Number
- Unity客户端模块划分
- Android SDK 开发范例大全 ---3.8手机页面的转换