ios - Use right to left UIScreenEdgePanGestureRecognizer on UITableView that has section indexes -


i want add uiscreenedgepangesturerecognizer uitableview can edge swipe right side go next screen in controller hierarchy.

this works fine except when table view has section indexes shown on side. in case, section index area handles touches, can't swipe edge. able support both edge pan , section index tap , vertical pan functionality.

i tried adding view on top of uitableview handle swipe, handles touches , table view no longer gets anything.

okay, tried bunch of stuff , came non-ideal working solution.

the first part of problem section index in own view subview of uitableview. captures touches or gesture recognizers might add uitableview.

the second problem section index view not part of public api.

so solution add uiscreenedgepangesturerecognizer section index view.

the view instance of private class uitableviewindex. created uitableview extension:

extension uitableview {     var sectionindexview: uiview? {         view in self.subviews {             if view.classname() == "uitableviewindex" {                 return view             }         }         return nil     } } 

note above code fragile , not future proof, because if apple changes class name or location in view hierarchy no longer work. in case edge swipe convenience feature, , there "next" button @ top of screen. in addition, of view controllers don't have table index, if stopped working on few screens. if solution doesn't work in future it's not huge deal.

i wrote convenience function edge gesture recognizer view:

extension uiview {     var screenedgepangesturerecognizer: uiscreenedgepangesturerecognizer? {         guard let gestures = self.gesturerecognizers else {             return nil         }         gesture in gestures {             if let edgepan = gesture as? uiscreenedgepangesturerecognizer {                 return edgepan             }         }         return nil     } } 

i add uiscreenedgepangesturerecognizer uitableview in viewdidload method of view controller.

finally, in viewdidappear of view controller check see if gesture recognizer has been added section index view. if hasn't, add there. need @ point after section index has been added table view - i.e. not in viewdidload. , need make sure you're not adding gesture recognizer multiple times.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -