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索引
    MS SQL存储过程编写经验和优化措施
    ASP調用存講過程總結
    調用外部的DLL(DllImportAttribute)
    MS SQL中的行轉列
    SQL Server乐观锁定和悲观锁定实例
    如何使用 JScript 從 HTML 網頁自動化 Excel
    了解SQL Server锁争用:NOLOCK 和 ROWLOCK 的秘密
    C#語法學習結構(Struct)
    四项技术 助你提高SQL Server的性能
  • 原文地址:https://www.cnblogs.com/mystory/p/2882079.html
Copyright © 2011-2022 走看看