'''
class TestViewController: ViewController ,UIGestureRecognizerDelegate {
var viewModel = NewsViewModel<NewsPageModel>(service: NewsRecordService())
var items = [NewsPageModel.T]()
let leftView = UIView()
var isOpen = false
private let headerRefreshTrigger = PublishSubject<Void>()
private let footerRefreshTrigger = PublishSubject<Void>()
private let normalRefreshTrigger = SubscribeManager.shared.NewsRefreshTrigger
private let emptyRefreshTrigger = PublishRelay<Void>()
private let uiChangePublish = PublishSubject<Void>()
var itemWitdh:CGFloat = 432
var minLimiteWitdh:CGFloat = 360
var currentWitdh:CGFloat = 0.0
private lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 16
layout.minimumLineSpacing = 16
layout.sectionInset = UIEdgeInsets(top: 20, left: 18, bottom: 20, right: 18)
layout.itemSize = CGSize(width: UIDevice.caculateWitdh(maign: 18, space: 16, itemWitdh: 432, totalWitdh: view.width), height: 148)
layout.scrollDirection = .horizontal
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.backgroundColor = .clear
collectionView.showsHorizontalScrollIndicator = false
collectionView.isScrollEnabled = true
collectionView.delegate = self
if #available(iOS 11, *) {
collectionView.contentInsetAdjustmentBehavior = .never
}
collectionView.register(cellType: NewsCollectCell.self)
collectionView.mj_header = RefreshHeader(refreshingBlock: {[weak self] in
guard let self = self else { return }
self.headerRefreshTrigger.onNext(())
})
collectionView.mj_footer = RefreshFooter(refreshingBlock: {[weak self] in
guard let self = self else { return }
self.footerRefreshTrigger.onNext(())
})
return collectionView
}()
override func viewDidLoad() {
super.viewDidLoad()
hbd_barHidden = true
setupUI()
setupBinding()
}
func freshData() {
self.normalRefreshTrigger.onNext(())
}
func setupUI() {
view.backgroundColor = .init(hex: "#F5F6F9")
view.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.top.right.equalToSuperview().offset(0)
make.bottom.equalTo(view.snp_bottomMargin).offset(0)
}
view.addSubview(leftView)
leftView.backgroundColor = .greenColor
leftView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(0)
make.bottom.equalTo(view.snp_bottomMargin).offset(0)
make.left.equalToSuperview().offset(-200)
make.width.equalTo(200)
}
let pan = UIPanGestureRecognizer.init(target: self, action: #selector(panGes))
pan.delegate = self
self.view.addGestureRecognizer(pan)
}
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer.view?.isDescendant(of: collectionView) == true {
return false
}
if gestureRecognizer is UIScreenEdgePanGestureRecognizer {
return false
}else{
let xx = gestureRecognizer.location(in: view).x
if !isOpen {
if xx < 100 {
return true
}
}else{
if xx > 200 {
return true
}
}
}
return false
}
@objc
func panGes(ges:UIPanGestureRecognizer) {
var xx = ges.translation(in: ges.view).x
print("x=====\(xx)")
switch ges.state {
case .began:
break
case .changed :
if !isOpen {
if xx > 0 {
if xx > 200 {
xx = 200
}
leftView.snp.updateConstraints { make in
make.left.equalToSuperview().offset(-200 + xx)
}
}
}else{
if xx < 0 {
if xx < -200 {
xx = -200
}
leftView.snp.updateConstraints { make in
make.left.equalToSuperview().offset(xx)
}
}
}
default:
if isOpen {
if xx < -50 {
UIView.animate(withDuration: 0.25) {
self.leftView.snp.updateConstraints { make in
make.left.equalToSuperview().offset(-200)
}
} completion: { complete in
self.isOpen = false
}
}
}else{
if xx > 50 {
UIView.animate(withDuration: 0.25) {
self.leftView.snp.updateConstraints { make in
make.left.equalToSuperview().offset(0)
}
} completion: { complete in
self.isOpen = true
}
}
}
}
}
'''