mikefrederick / MFSideMenu

Facebook-like side menu for iOS
Other
1.17k stars 291 forks source link

Recreation of GestureRecognizer #144

Open michaelbanholzer opened 10 years ago

michaelbanholzer commented 10 years ago

Nice sidemenu, well done! Thanks!

But why do you recreate a new gestureRecognizer every time the methods centerTapGestureRecognizer and panGestureRecognizer in MFSideMenuContainerViewController are called? Maybe you'll overflood the view with gestureRecognizers!

Thus the method removeCenterGestureRecognizers is meaningless, since removeGestureRecognizer: takes the new allocated gestureRecognizer and not the attached recognizer! I.e. you can keep them with instance variables

keeshux commented 10 years ago

+1, the panGestureRecognizer getter is even misleading because I'd expect it to return the currently attached recognizer.

mikefrederick commented 10 years ago

@michaelbanholzer @keeshux I agree that it is misleading to return a new gesture recognizer every time that panGestureRecognizer is called. The reason I did this at the time was that the library needed a way to add the pan gesture to any custom view, and you can only add an instance of a UIGestureRecognizer to one view. So each view that you add the pan gesture to needs it's own instance of the UIPanGestureRecognizer. If panGestureRecognizer was a class method instead of an instance method it might be more straightforward.

keeshux commented 10 years ago

Instance method is the right choice here, just give it a different name. E.g. use panGestureRecognizer for the one you attach to your own view and provide something like attachablePanGestureRecognizer for custom external views.

keeshux commented 10 years ago

P.S.: you can internally reuse the attachable method to also create your recognizers, the important bit is: only create yours once, but leave the user a way to create any.