【iOS开发系列】scrollView中的directionalLockEnabled
来源:互联网 发布:朝鲜的未来 知乎 编辑:程序博客网 时间:2024/05/28 15:19
scrollView中的directionalLockEnabled的功能本来就是用来让用户每次只在一个方向上滚动,竖直或者水平,但是如果初始移动方向处于45°左右的时候,这个锁就失效了。
苹果官方发现了这个问题,在官方文档里有如下描述,但是没有解决:
"If this property is NO
, scrolling is permitted in both horizontal and vertical directions. If this property is YES
and the user begins dragging in one general direction (horizontally or vertically), the scroll view disables scrolling in the other direction. If the drag direction is diagonal, then scrolling will not be locked and the user can drag in any direction until the drag completes. The default value is NO
"
这是stackoverflow上的讨论:http://stackoverflow.com/questions/728014/uiscrollview-paging-horizontally-scrolling-vertically
@property (nonatomic) CGPoint scrollViewStartPosPoint;@property (nonatomic) int scrollDirection;@synthesize scrollViewStartPosPoint = _scrollViewStartPosPoint;@synthesize scrollDirection = _scrollDirection;- (id)initWithFrame:(CGRect)frame{ _scrollDirection = 0;}- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (self.scrollDirection == 0){//we need to determine direction //use the difference between positions to determine the direction. if (abs(self.scrollViewStartPosPoint.x-scrollView.contentOffset.x)< abs(self.scrollViewStartPosPoint.y-scrollView.contentOffset.y)){ //Vertical Scrolling self.scrollDirection = 1; } else { //Horitonzal Scrolling self.scrollDirection = 2; } } //Update scroll position of the scrollview according to detected direction. if (self.scrollDirection == 1) { scrollView.contentOffset = CGPointMake(self.scrollViewStartPosPoint.x,scrollView.contentOffset.y); } else if (self.scrollDirection == 2){ scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x,self.scrollViewStartPosPoint.y); }}- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { self.scrollViewStartPosPoint = scrollView.contentOffset; self.scrollDirection = 0;}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { if (decelerate) { self.scrollDirection =0; }}- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { self.scrollDirection =0;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; // always forward touchesBegan -- there's no way to forward it later// if (_isHorizontalScroll)// return; // UIScrollView is in charge now// if ([touches count] == [[event touchesForView:self] count]) { // initial touch// _originalPoint = [[touches anyObject] locationInView:self];// _currentChild = [self honestHitTest:_originalPoint withEvent:event];// _isMultitouch = NO;// }// _isMultitouch |= ([[event touchesForView:self] count] > 1);// [_currentChild touchesBegan:touches withEvent:event];}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event];// if (!_isHorizontalScroll && !_isMultitouch) {// CGPoint point = [[touches anyObject] locationInView:self];// if (fabsf(_originalPoint.x - point.x) > kThresholdX && fabsf(_originalPoint.y - point.y) < kThresholdY) {// _isHorizontalScroll = YES;// [_currentChild touchesCancelled:[event touchesForView:self] withEvent:event]// }// }// if (_isHorizontalScroll)// [super touchesMoved:touches withEvent:event]; // UIScrollView only kicks in on horizontal scroll// else// [_currentChild touchesMoved:touches withEvent:event];}
1 0
- 【iOS开发系列】scrollView中的directionalLockEnabled
- iOS的scrollView属性directionalLockEnabled的问题修正
- iOS: UIScrollView的属性directionalLockEnabled
- iOS中的ScrollView
- iOS中的ScrollView
- IOS自动布局进阶系列视频教程-02scrollView自动布局中的应用
- IOS开发-ScrollView设置
- iOS开发-Scrollview属性详解
- IOS系列——scrollview自动滚动
- iOS Scrollview中的AutoLayout(纯IB)
- IOS系列——iPhone开发中的技巧整理
- ios开发系列之Core Graphics中的CGContext
- ios开发scrollview不能横向移动
- 【iOS开发】ScrollView的一些常用属性
- IOS开发指南读书笔记7(ScrollView)
- iOS 开发系列教程
- IOS开发工具系列
- ios 开发系列(网址)
- 工作日志 7.21
- 使用LZMA算法(转载)
- 深入分析C++引用
- 常用的Http状态码
- [JSON] JSON入门指南
- 【iOS开发系列】scrollView中的directionalLockEnabled
- maven 加入json-lib.jar 报错 Missing artifact net.sf.json-lib:json-lib:jar:2.4:compile
- Java关于集合(list,set,map)的遍历与增强for循环的使用
- 2.第三单元任务一实训:有一个数列:8、4、2、1、23、344、12,编辑实现以下功能。循环输出数列的值;求数列中所有数值的和;猜数游戏:从键盘中任意输入一个数据,判断数列中是否包含该数。
- 笔试宝典上关于字符串复制的问题
- 走迷宫
- 淘宝的数据解决方案:datax - DataX产品说明
- FLATRO OPENCART 自适应多用途主题模板 ABC-0054
- socket原理