UIScrollView筆記

  1. UIScrollView必須知道它的contentsize,這就是為啥TableView的row的height必須被計(jì)算,即使那些row還沒有出現(xiàn)在屏幕。

The scroll view must know the size of the content view so it knows when to stop scrolling; by default, it “bounces” back when scrolling exceeds the bounds of the content

  1. 為了確定用戶是在點(diǎn)擊還是在滑動(dòng),UIScrollView自己維護(hù)了一個(gè)計(jì)時(shí)器,并記錄手指的位置。如果計(jì)時(shí)器相應(yīng)之前,還沒有比較顯著的移動(dòng),那么UIScrollView就發(fā)送觸摸時(shí)間到相應(yīng)的subview;否則就滑動(dòng)自己。
  2. scrollsToTop
    當(dāng)用戶輕點(diǎn)狀態(tài)欄時(shí),系統(tǒng)會(huì)要求離狀態(tài)欄近的scrollview把自己的內(nèi)容滑到最上面。如果這個(gè)屬性是false,就會(huì)忽略這個(gè)請(qǐng)求。

On iPhone, the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to true.

  1. 設(shè)置特定區(qū)域可見
scrollRectToVisible(_ rect: CGRect, animated: Bool)
  1. 設(shè)置分頁
scrollView.pagingEnabled = true

當(dāng)停止滑動(dòng)時(shí),會(huì)停到scrollview的大小的整數(shù)倍


設(shè)置分頁
  1. 設(shè)置方向鎖定。
    一般來說,scrollview可以在橫向、縱向滑動(dòng)。設(shè)定鎖定以后,就只能在一個(gè)方向鎖定了。在哪個(gè)方向鎖定要看在哪個(gè)方向移動(dòng)的距離大。
        scrollView.directionalLockEnabled = true
ggfg.gif
  1. Scroll Indicator
    就是滑動(dòng)時(shí)出現(xiàn)的那條線
        scrollView.indicatorStyle = .Black
        scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 5, 10, 30)
        button.addTarget(self, action: #selector(ViewController.flashIndicator(_:)), forControlEvents: .TouchUpInside)
    func flashIndicator(sender:UIButton) -> Void {
        scrollView.flashScrollIndicators()
    }
Indicator
  1. 和鍵盤的交互
var keyboardDismissMode: UIScrollViewKeyboardDismissMode { get set 
  • none
  • onDrag: drag開始時(shí)就消失
  • interactive: The keyboard follows the dragging touch offscreen, and can be pulled upward again to cancel the dismiss。


    UIScrollViewKeyboardDismissModeInteractive
  1. UIScrollViewDelegate調(diào)用順序
  • 滑動(dòng),然后放開
    scrollViewWillBeginDragging
    幾次scrollViewDidScroll
    scrollViewWillEndDragging(:withVelocity:targetContentOffset:)
    scrollViewDidEndDragging(
    :willDecelerate:)
    scrollViewWillBeginDecelerating
    若干scrollViewDidScroll
    scrollViewDidEndDecelerating
  • 滑動(dòng),scrollview不動(dòng),然后放開
    scrollViewWillBeginDragging
    幾次scrollViewDidScroll
    scrollViewWillEndDragging
    scrollViewDidEndDragging
  1. isDragging, isTracking
  • 滑動(dòng),然后放開
    scrollViewWillBeginDecelerating之后,istracking變?yōu)閒alse
    scrollViewDidEndDecelerating之前,isdragging為true
  • 滑動(dòng),scrollview不動(dòng),然后放開
    isTrackiing一直是true
    isdragging在scrollViewWillEndDragging之前是true
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容