iOS UISlider滑动块触摸范围调整变大
正常情况下,我们自定义的滑动区域都不会太大,否则UI不美观,但是这样,又会手势不灵敏,用户体验变差。
如何解决?
这里有一种方案:封装一个继承UISlider的自定义类,重写thumbRectForBounds方法,原理就是对thumb区域rect进行放大处理。
代码如下:
1、新建一个类,继承UISlider
h文件:
#import <UIKit/UIKit.h> @interface DBSlider : UISlider @end
m文件:
#import "DBSlider.h" #define thumbBound_x 10
#define thumbBound_y 20 @interface DBSlider ()
{
CGRect lastBounds;
} @end @implementation DBSlider - (CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value
{ rect.origin.x = rect.origin.x;
rect.size.width = rect.size.width ;
CGRect result = [super thumbRectForBounds:bounds trackRect:rect value:value]; lastBounds = result;
return result;
} - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{ UIView *result = [super hitTest:point withEvent:event];
if (point.x < 0 || point.x > self.bounds.size.width){
return result;
}
if ((point.y >= -thumbBound_y) && (point.y < lastBounds.size.height + thumbBound_y)) {
float value = 0.0;
value = point.x - self.bounds.origin.x;
value = value/self.bounds.size.width;
value = value < ? : value;
value = value > ? : value;
value = value * (self.maximumValue - self.minimumValue) + self.minimumValue;
[self setValue:value animated:YES];
}
return result;
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
BOOL result = [super pointInside:point withEvent:event];
if (!result && point.y > -10) {
if ((point.x >= lastBounds.origin.x - thumbBound_x) && (point.x <= (lastBounds.origin.x + lastBounds.size.width + thumbBound_x)) && (point.y < (lastBounds.size.height + thumbBound_y))) {
result = YES;
}
}
return result;
}
@end
代码直接拷贝即可。
如果你已经用UISlider画好了控件:
1、如果是代码创建,直接更改类名-UISlider -> DBSlider
2、如果是xib,修改控件的Custom Class, 再重新连线就可以了,其他都不用改。

iOS UISlider滑动块触摸范围调整变大的更多相关文章
- iOS:步进UIStepper、滑动块UISlider、开关UISwitch的基本使用
步进UIStepper.滑动块UISlider:当它们作为事件,被触发时,它们的值会发生改变.正因为如此,触发该事件时,可以一张一张翻阅浏览图片,,,, 步进UIStepper: @property( ...
- 毫无保留开源我写的:IOS Android Ipad 多点触摸通用js 库
毫无保留开源我写的:IOS Android Ipad 多点触摸通用js 库 在线演示地址: http://m.yunxunmi.com/ 支持 IOS Android Ipad 等不同操作系统的手持或 ...
- 类似IOS的滑动返回上一级,SwipeBackLayout-android的滑动返回类库
最近,公司在开发App的需求中增加了一个新的需求,要在android的页面中增加向右滑动的时候返回上一级页面.我刚知道这个需求的时候,感觉有点坑,可能设计那边最近接触到知乎的客户端或者是IOS的滑动可 ...
- iframe ios中h5页面 样式变大
实际项目开发中,iframe在移动设备中使用问题还是很大的,说一说我的那些iframe坑 做过的这个后台管理框架,最开始的需求是PC,但随着业务需要,需要将项目兼容到ipad,后台的框架也是使用的开源 ...
- iOS学习笔记之触摸事件&UIResponder
iOS学习笔记之触摸事件&UIResponder 触摸事件 与触摸事件相关的四个方法如下: 一根手指或多根手指触摸屏幕 -(void)touchesBegan:(NSSet *)touches ...
- Android模仿三星手机系统滑动条滑动时滑块变大的特效
使用三星手机的过程中发现三星手机系统自带的滑动条有一个特效.比方调节亮度的滑动条.在滑动滑块的过程中,滑块会变大.功能非常小可是体验却非常好,于是决定做一个这种效果出来.好了废话不多说了,以下開始实现 ...
- 解决页面使用overflow: scroll,overflow-y:hidden在iOS上滑动卡顿的问题
解决页面使用overflow: scroll,overflow-y:hidden在iOS上滑动卡顿的问题 div{ width: 100%; overflow-y: hidden; -webkit-o ...
- 记 页面使用overflow-scroll在iOS上滑动卡顿的问题
页面使用overflow-scroll在iOS上滑动卡顿的问题 因在做一个滑动的list列表,为某个div使用了overflow: scroll属性. 结果在手机上测试时,ios手机有明显的滑动卡顿问 ...
- 解决overflow: auto在Ios中滑动不流畅
[bug]—— H5页面在 ios 端滑动不流畅的问题 IOS系统的惯性滑动效果非常6,但是当我们对div加overflow-y:auto;后是不会出这个效果的,滑动的时候会感觉很生涩.怎么办? ...
随机推荐
- iOS开发-UIRefreshControl下拉刷新
下拉刷新一直都是第三库的天下,有的第三库甚至支持上下左右刷新,UIRefreshControl是iOS6之后支持的一个刷新控件,不过由于功能单一,样式不能自定义,因此不能满足大众的需求,用法比较简单在 ...
- 基于Bootstrap+jQuery.validate Form表单验证实践
基于Bootstrap jQuery.validate Form表单验证实践 项目结构 : github 上源码地址:https://github.com/starzou/front-end- ...
- js改变iframe 的src地址
<script> function dizhi(){ document.getElementById("aaa").src='http://www.sohu.com' ...
- jquery事件使用方法总结 (转)
http://www.cnblogs.com/cwp-bg/p/7668940.html jquery提供了许多的事件处理函数,学习前端一段时间了,下面对其总结一下,梳理一下知识点. 一.鼠标事件 1 ...
- Mybatis源码分析之Cache二级缓存原理 (五)
一:Cache类的介绍 讲解缓存之前我们需要先了解一下Cache接口以及实现MyBatis定义了一个org.apache.ibatis.cache.Cache接口作为其Cache提供者的SPI(Ser ...
- 使用jstl报错:Can not find the tag library descriptor for “http://java.sun.com/jstl/core”
使用jstl报错:Can not find the tag library descriptor for “http://java.sun.com/jstl/core” 出现这个错误的原因是项目中没有 ...
- 我的webrequest经验
1 webrequest 是什么:编程方式模拟web请求,利用webrequest可以实现 相当于一个浏览器请求一个网页的效果,但是它始终是模拟请求, 与浏览器输入框输入网址请求不一样. 2 程序设计 ...
- VCAP5-DCA Objective 1.3 – Configure and Manage Complex Multipathing and PSA Plug-ins
http://virtuallyhyper.com/2012/10/vcap5-dca-objective-1-3-configure-and-manage-complex-multipathing- ...
- C语言读取 未知长度 的矩阵
1.确定矩阵行数: 使用每次读取一行函数fgets - row = 0; while(fgets(buf, buflen, fp) != NULL) row++; - 2.确定矩阵列数: - re ...
- Pause Web Sessions
To pause specific sessions, add rules using FiddlerScript to the OnBeforeRequest function (except wh ...