Last active
May 5, 2018 07:25
-
-
Save tyrad/2e0a1bfced85f78bcc003a8edafb37e3 to your computer and use it in GitHub Desktop.
仿高德地图搜索结果页面
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func someMethod(){ | |
vc.panGesstrueCallBack { [weak self](offset, ges, vc ,tableView ,isDragUp) in | |
guard let strongSelf = self else { return } | |
guard let targetV = self?.targetView else { return } | |
var isScrollingTableView = false //正在滚动 | |
if vc.view.frame.size.height >= targetV.frame.size.height && isDragUp { | |
isScrollingTableView = true | |
}else if vc.view.frame.size.height >= targetV.frame.size.height && tableView.contentOffset.y != 0 { | |
isScrollingTableView = true | |
}else { | |
isScrollingTableView = false | |
} | |
tableView.canScroll = isScrollingTableView | |
switch ges.state { | |
case .began: | |
self?.originHeight = vc.view.frame.height | |
self?.originTableOffset = tableView.contentOffset.y | |
case .changed: | |
if tableView.canScroll /*isScrollEnabled*/ { | |
return | |
} | |
let originHeight = strongSelf.originHeight | |
var currentHeight = originHeight - (offset - strongSelf.originTableOffset) | |
//限制最大高度 | |
if currentHeight > targetV.frame.size.height { | |
currentHeight = targetV.frame.size.height | |
} | |
vc.view.snp.remakeConstraints({ (make) in | |
make.left.right.bottom.equalTo(targetV) | |
make.height.equalTo(currentHeight) | |
}) | |
case .ended: | |
let originHeight = strongSelf.originHeight | |
if tableView.canScroll { | |
return | |
} | |
//滚动的生效阈值,不满足条件返回原始值 | |
if abs(offset) < 30 { | |
vc.view.snp.remakeConstraints({ (make) in | |
make.left.right.bottom.equalTo(targetV) | |
make.height.equalTo(originHeight) | |
}) | |
UIView.animate(withDuration: 0.3) { | |
targetV.layoutIfNeeded() | |
} | |
}else { | |
//原始比例 | |
let origPercent = originHeight/targetV.frame.size.height | |
let isDragUp = (offset - strongSelf.originTableOffset) < 0 //上拉 | |
//三段式 33.33% 66.67% | |
var finalHeight:CGFloat = 30 | |
if origPercent > 0.667 { | |
if isDragUp { | |
finalHeight = targetV.frame.size.height | |
}else { | |
finalHeight = targetV.frame.size.height/2 | |
} | |
}else if origPercent > 0.33 { | |
if isDragUp { | |
finalHeight = targetV.frame.size.height | |
}else { | |
finalHeight = 30 | |
} | |
}else{ | |
if isDragUp { | |
finalHeight = targetV.frame.size.height/2 | |
}else { | |
finalHeight = 30 | |
} | |
} | |
vc.view.snp.remakeConstraints({ (make) in | |
make.left.right.bottom.equalTo(targetV) | |
make.height.equalTo(finalHeight) | |
}) | |
UIView.animate(withDuration: 0.3, animations: { | |
targetV.layoutIfNeeded() | |
}, completion: { (finish) in | |
}) | |
} | |
default: | |
return | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MapSearchDisplayTableView: BaseTableView { | |
//是否可以滚动 | |
var canScroll:Bool = false{ | |
didSet{ | |
self.showsVerticalScrollIndicator = canScroll | |
} | |
} | |
//代理方法略。。 | |
//监听滚动 | |
func scrollViewDidScroll(_ scrollView: UIScrollView) { | |
if canScroll == false { | |
scrollView.contentOffset = CGPoint.zero | |
} | |
//滑动到顶端 | |
if scrollView.contentOffset.y <= 0 { | |
canScroll = false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment