开发者

iOS/iPhone best practice for handling events

开发者 https://www.devze.com 2023-01-11 15:00 出处:网络
I am just starting out with iOS programming. I\'m currently looking through the MoveMe example and had a question about event handlers.

I am just starting out with iOS programming. I'm currently looking through the MoveMe example and had a question about event handlers.

In the example, they have the MoveMeView (subclass of UIView) handle events (touchesBegan:withEvent:, etc.). It seems like this belongs on a controller though, not the view. Is there a standard way of doing this, or any guidelines on the divisi开发者_开发百科on of responsibility between a view and a controller?


Touch handling is in the responsibility of the view. Just like you I think it should be on some kind of controller and Apple luckily introduced UIGestureRecognizer in iOS3.2. If you are targeting anything below 3.2 you'll have to stick with the touchesBegan/Moved/Ended methods, or create something for yourself.

For targets after 3.2 please take a look at UIGestureRecognizer and it's subclasses and read the Gesture Recognizers chapter in the Event Handling Guide. It's also possible you create your own subclass, if you have touch handling needs not covered by the shipping gesture Recognizers.

0

精彩评论

暂无评论...
验证码 换一张
取 消