iOS UIScrollView和控制器返回手勢沖突解決方法
開發(fā)中,有部分UI,會(huì)將UIScrollView橫向鋪在底層,上面放tableView 或一些視圖左右滾動(dòng)切換,底層的scrollView會(huì)和Nav ViewController原有的返回手勢沖突
解決辦法,重寫UIScrollView 的gestureRecognizerShouldBegin,在ScrollView滾動(dòng)到頭的時(shí)候,屏蔽ScrollView的手勢
class GesturesConflictScrollView: UIScrollView { override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { back(by: gestureRecognizer) } private final func back(by gestureRecognizer: UIGestureRecognizer) -> Bool {guard gestureRecognizer == panGestureRecognizer else { return true } // point.x < 0 代表左滑即手指從屏幕右向左移動(dòng) 反之一樣 let point: CGPoint = panGestureRecognizer.translation(in: self) let state: UIGestureRecognizer.State = gestureRecognizer.state let locDistance: CGFloat = UIScreen.main.bounds.size.widthif state == .began || state == .possible { let locationPoint = gestureRecognizer.location(in: self) if point.x > 0 && locationPoint.x < locDistance && contentOffset.x <= 0 {return false } let pageCount = contentSize.width / UIScreen.main.bounds.size.width let criticalPoint = pageCount < 2 ? locDistance : locDistance * (pageCount - 1) if point.x < 0 && contentOffset.x == criticalPoint {return false } } return true }}
到此這篇關(guān)于iOS UIScrollView和控制器返回手勢沖突解決方法的文章就介紹到這了,更多相關(guān)iOS UIScrollView和控制器手勢沖突內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP實(shí)現(xiàn)加法驗(yàn)證碼2. XML入門的常見問題(四)3. 簡單了解XML 樹結(jié)構(gòu)4. XHTML 1.0:標(biāo)記新的開端5. 三個(gè)不常見的 HTML5 實(shí)用新特性簡介6. 怎樣才能用js生成xmldom對象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?7. ASP中if語句、select 、while循環(huán)的使用方法8. XML解析錯(cuò)誤:未組織好 的解決辦法9. 概述IE和SQL2k開發(fā)一個(gè)XML聊天程序10. CSS3使用過度動(dòng)畫和緩動(dòng)效果案例講解
