Following on from iPhone Annoyances
I decided to investigate the cause of the release jumping that I'm experiencing when scrubbing.
I was puzzled at what causes the jumping so I wrote a little app "TouchTest
" which tests the touch actions in IOS. My plan is to attempt to replicate the coordinate changes that occur when I release a touch.
* Cocoa Touch
Cocoa Touch is the application framework used in writing IOS applications. It is part of Apple's SDK. Cocoa Touch follows the concept of Model-View-Controller (MVC) which you should be familiar with as it's the weapon of choice in most UI focused frameworks. Ruby on Rails
, ASP.NET MVC
to name a few.
* The Code
The nuts and bolts of the of the application are in my custom UIView
Even if you are not familiar with Objective-C I think the code is quite easy to read & understand.
The app displays the X & Y coordinates of the previous and current touches. To accomplish this I define 2 UILabels
) for display purposes and 2 CGPoint
data structures (previousTouch
) which provides X & Y floating point accessors.
drawRect: is the method that is called every time [self setNeedsDisplay] is called. It simply draws a small circle on the display at the coordinates of the current touch. It also messages 'updateLabels'.
updateLabels: does exactly that. Updates the text attributes of both previousTouchLabel & currentTouchLabel. The updated text is immediately displayed on screen.
The real work is being done in the "touches*:withEvent:" methods that are inherited from the UIResponder
Class. By overriding these methods I can intercept all beginning, moving and ending touches.
The three touch methods are almost identical. In fact "touchesBegin: withEvent:" & "touchesMoved: withEvent:" are identical.
'touches' contains a collection of up to 5 UITouch objects (one for each finger that touches the screen). I'm only interested in the 1st one ( I'm only going to be touching the display with one finger) so I pop the 1st touch event off the collection and store it in our local variable touch.
Next I make previousTouch equal to the current value of currentTouch before updating currentTouch with the coordinates of our touch object.
Finally I call 'setNeedDisplay' to redraw the display.
touchesEnd: withEvent: has slightly more code as we also perform a rough calculation to find the difference between the 'previousTouch' and 'currentTouch' points. the resulting output goes to our debug window.
* The Test
XCode comes with a brilliant simulator called 'IOS simulator'. It's a software instance of an iPhone or iPad.
I can move the mouse around the simulated iPhone and click away. I see for the most part the previous & current value remain identical for most clicks. I can get different values if I drag the mouse during a click.
The simulator however is not ideal when testing touch events as the mouse is not a fat finger. It's easy to click on a mouse without moving it.
When I fire up the code on my iPhone (just as easy as running on the simulator) I can immediately simulate the issue I see when I'm scrubbing in the music app. Even when tapping the screen quickly the majority of my touches previous and current are not equal.