UIScrollView笔记

  1. UIScrollView必须知道它的contentsize,这就是为啥TableView的row的height必须被计算,即使那些row还没有出现在屏幕。

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. 为了确定用户是在点击还是在滑动,UIScrollView自己维护了一个计时器,并记录手指的位置。如果计时器相应之前,还没有比较显著的移动,那么UIScrollView就发送触摸时间到相应的subview;否则就滑动自己。
  2. scrollsToTop
    当用户轻点状态栏时,系统会要求离状态栏近的scrollview把自己的内容滑到最上面。如果这个属性是false,就会忽略这个请求。

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. 设置特定区域可见
scrollRectToVisible(_ rect: CGRect, animated: Bool)
  1. 设置分页
scrollView.pagingEnabled = true

当停止滑动时,会停到scrollview的大小的整数倍


设置分页
  1. 设置方向锁定。
    一般来说,scrollview可以在横向、纵向滑动。设定锁定以后,就只能在一个方向锁定了。在哪个方向锁定要看在哪个方向移动的距离大。
        scrollView.directionalLockEnabled = true
ggfg.gif
  1. Scroll Indicator
    就是滑动时出现的那条线
        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开始时就消失
  • interactive: The keyboard follows the dragging touch offscreen, and can be pulled upward again to cancel the dismiss。


    UIScrollViewKeyboardDismissModeInteractive
  1. UIScrollViewDelegate调用顺序
  • 滑动,然后放开
    scrollViewWillBeginDragging
    几次scrollViewDidScroll
    scrollViewWillEndDragging(:withVelocity:targetContentOffset:)
    scrollViewDidEndDragging(
    :willDecelerate:)
    scrollViewWillBeginDecelerating
    若干scrollViewDidScroll
    scrollViewDidEndDecelerating
  • 滑动,scrollview不动,然后放开
    scrollViewWillBeginDragging
    几次scrollViewDidScroll
    scrollViewWillEndDragging
    scrollViewDidEndDragging
  1. isDragging, isTracking
  • 滑动,然后放开
    scrollViewWillBeginDecelerating之后,istracking变为false
    scrollViewDidEndDecelerating之前,isdragging为true
  • 滑动,scrollview不动,然后放开
    isTrackiing一直是true
    isdragging在scrollViewWillEndDragging之前是true
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容