在一些時(shí)候隱藏了NavigationBar的時(shí)候,卻又想使用系統(tǒng)的側(cè)滑返回,調(diào)用了navigationController?.interactivePopGestureRecognizer?.delegate = self
這樣雖然是可以返回,但是后面發(fā)現(xiàn)這個(gè)方法有 bug ,就是在一級(jí)頁(yè)面卻還能繼續(xù)往上返回,這樣導(dǎo)致 rootviewcontrol 被彈出去了,app界面卡死不動(dòng),卻不是異常閃退.
找了一下解決方法如下,在 rootviewcontrol 的頁(yè)面遵尋UIGestureRecognizerDelegate方法
然后在viewWillAppear里面實(shí)現(xiàn)navigationController?.interactivePopGestureRecognizer?.delegate = self
最后添加
?funcgestureRecognizerShouldBegin(_gestureRecognizer:UIGestureRecognizer) ->Bool{
? ? }
就可以了.
完整代碼如下
override func viewWillAppear(_animated:Bool) {
? ? ? ? navigationController?.interactivePopGestureRecognizer?.delegate = self
? ? }
func gestureRecognizerShouldBegin(_gestureRecognizer:UIGestureRecognizer) ->Bool{
? ? ? ? if let viewControls = navigationController?.viewControllers{
? ? ? ? ? ? if viewControls.count>1{
? ? ? ? ? ? ? ? return true
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return false
? ? }