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;后是不会出这个效果的,滑动的时候会感觉很生涩.怎么办? ...
随机推荐
- 利用vue-cropper做的关于图片裁剪、压缩、上传、预览等做的一个公共组件
公共组件: <template> <div> <div class="upload-box"> <div class="imag ...
- Python3 OpenCV应用
1.openCV介绍 openCV:Open Source Computer Vision Library.OpenCV于1999年由Intel建立,如今由Willow Garage提供支持.Open ...
- 转:无监督特征学习——Unsupervised feature learning and deep learning
http://blog.csdn.net/abcjennifer/article/details/7804962 无监督学习近年来很热,先后应用于computer vision, audio clas ...
- 网易的Spark技术实践
http://www.infoq.com/cn/news/2014/04/netease-spark-practice?utm_source=infoq&utm_medium=popular_ ...
- [React] Write a stateful Component with the React useState Hook and TypeScript
Here we refactor a React TypeScript class component to a function component with a useState hook and ...
- cyml
bin/kafka-topics.sh --create --replication-factor 1 --partitions 1 --topic mc_logger2 --zookeeper lo ...
- FIS.js前端开发的使用说明文档
文档结构 什么是FIS 部署FIS FIS基本使用 模块定义 加载方式 调用Tangram 2.0 一.什么是FIS FIS提供了一套贯穿开发流程的开发体系和集成开发环境,为产品线提供前端开发底层架构 ...
- LintCode: Combination Sum II
C++ DFS class Solution { public: void help(vector<int> &a, int now, int sum, int target, v ...
- SharePoint 2010 匿名用户调用Client Object Model访问列表项
最近有个小需求,在门户首页上加个通知公告的版块,新闻来源是列表项,需要有垂直滚动的效果. 第一个想法就是通过SharePoint的Client Object Model获取列表数据再加上JQuery来 ...
- Linux实现多线程高速下载
使用Wget下载,有时候速度挺慢的. 有没有好办法呢? 一.解决方案 安装axel 安装方法: yum -y install epel-release .el7.x86_64.rpm rpm -ivh ...