問題:橫向可滾動(dòng)的 UIscrollview上面有添加其他VC頁面,其中有UITableview
- 1、創(chuàng)建Scrollview 的子類,實(shí)現(xiàn)里面多手勢(shì)代理方法
class LCCenterScrollView: UIScrollView,UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer.state.rawValue != 0 {
return true
}
return false
}
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
if indexPath.section == 0 {
return true
}
return false
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
if indexPath.section == 0 , indexPath.row < courses.count {
let model = courses[indexPath.row]
let topAction = UITableViewRowAction(style: .default, title: model.isTop ? "取消置頂":"置頂") { [weak self] (rowAction, indexP) in
guard let `self` = self else {return}
self.courseTop(model)
}
topAction.backgroundColor = MixedColor(styleV: ViewColorSet().V_BBBBBB).unfold()
let hideAction = UITableViewRowAction(style: .default, title: model.isHided ? "恢復(fù)":"隱藏") { [weak self] (rowAction, indexP) in
guard let `self` = self else {return}
self.courseHideRequest(model)
}
hideAction.backgroundColor = UIColor.zm_color(withHex: 0xff3b3d)
return [hideAction,topAction]
}
return nil
}
- 解決左滑 用力過猛 自動(dòng)調(diào)用做右邊的Action
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
if indexPath.section == 0 , indexPath.row < courses.count {
let model = courses[indexPath.row]
let topAction = UIContextualAction(style: .normal, title: model.isTop ? "取消置頂":"置頂") { [weak self] (action, sourceView, complete) in
guard let `self` = self else {return}
self.courseTop(model)
complete(true) // 注意:需要實(shí)現(xiàn)這個(gè)回調(diào),不然點(diǎn)擊后不會(huì)自動(dòng)收縮回去,效果有點(diǎn)僵硬
}
topAction.backgroundColor = MixedColor(styleV: ViewColorSet().V_BBBBBB).unfold()
let hideAction = UIContextualAction(style: .normal, title: model.isHided ? "恢復(fù)":"隱藏") { [weak self] (action, sourceView, complete) in
guard let `self` = self else {return}
self.courseHideRequest(model)
complete(true)
}
hideAction.backgroundColor = UIColor.zm_color(withHex: 0xff3b3d)
let actions = UISwipeActionsConfiguration(actions: [hideAction,topAction])
actions.performsFirstActionWithFullSwipe = false
return actions
}
return nil
}
- 處理 左滑編輯展開后,向右滑動(dòng)關(guān)閉左滑會(huì)觸發(fā)底部Uiscrollview 頁面切換
func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
self.superScrollview?.isScrollEnabled = false
}
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
self.superScrollview?.isScrollEnabled = true
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。