美文网首页
iOS 模仿抖音底部滚动分页按钮

iOS 模仿抖音底部滚动分页按钮

作者: 秋叶红90 | 来源:发表于2021-06-28 14:22 被阅读0次

底部按钮

IMG_52A4B353BBD3-1.jpeg

1 首先是一个scrollView

2 在scrollView 上加一个父视图 自定义一下名字为 MyCustomScrollView

import UIKit

class MyCustomScrollView: UIView {
    @IBOutlet weak var scrollView:UIScrollView?
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        let view = super.hitTest(point,with event:event)
        if (view == self) {
              return self.scrollView
        }
        return view
    }
}

3 让其scrollView 赋值给 父视图的 属性scrllView 意思就是越界之后的触摸事件,scrollView 在父视图上的位置为居中模式宽度 设为100 就可以了

4 scrollView的属性配置为

self.scrollView.isPagingEnabled = true
self.scrollView.clipsToBounds = false

相关文章

网友评论

      本文标题:iOS 模仿抖音底部滚动分页按钮

      本文链接:https://www.haomeiwen.com/subject/cmuqultx.html