zoukankan      html  css  js  c++  java
  • scrollViews

    一、scrollView中有一个有用的属性:@property(nonatomic) BOOL scrollsToTop;

    即点击status bar后会滚动到最顶部,尤其在tableview时好用,当内容很多时,滑动也很费劲,时常需要方便的回到最顶部。

    其官方解释是这样的:

    scrollsToTop

    A Boolean value that controls whether the scroll-to-top gesture is effective

    @property(nonatomic) BOOL scrollsToTop
    Discussion

    The scroll-to-top gesture is a tap on the status bar; when this property is YES, the scroll view jumps to the top of the content when this gesture occurs. The default value of this property is YES.

    This gesture works on a single visible scroll view; if there are multiple scroll views (for example, a date picker) with this property set, or if the delegate returns NO in scrollViewShouldScrollToTop:UIScrollView ignores the request. After the scroll view scrolls to the top of the content view, it sends the delegate a scrollViewDidScrollToTop: message.

    一般情况下是默认可以使用的,但是有例外,正如文档里写的:

    1、如果有多个scroll view 或者

    2、scrollViewShouldScrollToTop:返回NO

    则scrollToTop失效。

    默认2会返回YES,所以在多个scroll view的时候就不起作用了。

    那么在有多个scroll view的时候还想用这个方便的功能,该如何实现呢?

    在stackoverflow里找到了解决办法:

      一次只将一个scroll view的scrollsToTop属性设置为YES,其余设置为NO,则此scroll view就能响应scrollToTop的方法。

     二、Infinite scroll

    以有限的contentSize来实现无线的滚动,通过重写scrollView中的layoutSubView,在其内修改contentOffset来实现。

    三、Stationary scrollView

    在一个scrollView上有两个subview,让一个可以跟着scrollView滚动,另一个保持在屏幕的位置不变,也是通过修改contentOffset来实现。

    四、给scrollView中添加其他特殊手势

    scrollView中本身就有panGesture和swipeGesture,为了避免冲突,自己添加gesture后,通过

    - (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer  

    来使本身的手势失效。并且可以定义手势有效的范围,通过实现gesture的delegate中的一个方法

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

    来限制手势有效的范围。

    其中二、三、四的几个技术在wwdc2011 的Advanced ScrollView Techniques中有详细讲解。

  • 相关阅读:
    持有你自己的权力
    《活在恩典中》:我们所寻求的是什么?
    修学文钞 | 道证法师怎么学印光大师《文钞》
    致初学者:印祖文钞修学次第建议
    印光大师指定的文钞入门篇目
    sql注入在线检测(sqlmapapi)
    【转】Kali Linux 新手折腾笔记
    JAVA开发-我的第一个webScan扫描器
    JAVA开发--游戏24点
    JAVA开发--U盘EXE恢复工具
  • 原文地址:https://www.cnblogs.com/mystory/p/2882079.html
Copyright © 2011-2022 走看看