89.UIScrollView的一些不常用属性

来源:互联网 发布:淘宝买韩国专辑靠谱吗 编辑:程序博客网 时间:2024/05/30 05:24

今天来说关于UIScrollView的一些属性, 虽然不是特别常用但是有时候会有大作用的几个属性.

UIScrollView交互之键盘收回(keyboardDismissMode)

有些关于键盘收回的事件处理会写在UIScrollview的代理方法中,将要开始拖拽其时触发: -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
其实更简单的方法是通过设置UIScrollview的属性在其滑动时自动回收
scrollview.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
下面就来看看这个属性.

    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 375, 667)];    scrollView.backgroundColor = [UIColor lightGrayColor];    scrollView.contentSize = CGSizeMake(375, 3000);    [self.view addSubview:scrollView];    UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(0, 200, 100, 100)];    tf.backgroundColor = [UIColor greenColor];    [scrollView addSubview:tf];    //  UIScrollViewKeyboardDismissMode 枚举    scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

关于UIScrollViewKeyboardDismissMode枚举值:

UIScrollViewKeyboardDismissModeNone,
UIScrollViewKeyboardDismissModeOnDrag, // dismisses the keyboard when a drag begins
UIScrollViewKeyboardDismissModeInteractive, // the keyboard follows the dragging touch off screen, and may be pulled upward again to cancel the dismiss

第一个是默认值, None.
第二个, 当 UIScrollview 开始拖拽时, 便会收回键盘. 一般这个用的比较多
第三个, 当UIScrollview 拉至顶端后再次下拉, 便会收回键盘. 这个时机就类似于下拉刷新的操作时机.

UIScrollView事件传递(delaysContentTouches/cancelsContentTouches)

首先分析下当你的手指touch一个 UIScrollview开始,scrollView开始一个timer,如果:
1.150ms内如果你的手指没有任何动作,消息就会传给subView。
2.150ms内手指有明显的滑动(一个swipe动作),scrollView就会滚动,消息不会传给subView。
3.150ms内手指没有滑动,scrollView将消息传给subView,但是之后手指开始滑动,scrollView传送touchesCancelled消息给subView,然后开始滚动。

delaysContentTouches

@property(nonatomic) BOOL delaysContentTouches; // default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses

默认是YES,使用上面的150ms的timer,如果设置为NO,touch事件立即传递给subView,不会有150ms的等待。

cancelsContentTouches

@property(nonatomic) BOOL canCancelContentTouches; // default is YES. if NO, then once we start tracking, we don’t try to drag if the touch moves. this has no effect on presses

默认为YES,如果设置为NO,这消息一旦传递给subView,这scroll事件不会再发生。

0 0