Porting Letter Recognition Gesture Code from iOS to Windows 8 C#

Consider an educational app that teaches a child how to write letters.  The app may be interactive, allowing the child to swipe screens, pinch/zoom pictures, etc.  Now, what if the app was able to teach handwriting by recognizing if the child drew a particular letter?  I'm going to talk about how a developer can handle this scenario.  The goal here is to assume that iOS* code already exists for this and that it needs to be ported over to Windows 8* using the C# language.  If you are interested, read on!  The simple scenario below will be used for detecting the letter "R".

To follow along, check out my blog that discusses how to do this on the Windows 8 side:


Here, I'm going to present a simple porting guide from preexisting iOS code to the code shown in the link.  We start by noting that for iOS development, since letter recognition isn’t provided "out of the box," we need to subclass UIGestureRecognizerSubclass.h to create a custom gesture recognizer.  Here is a nice tutorial for the iOS side in case you aren't familiar with creating custom gestures:


 For Windows 8, note that in my blog above, I mentioned that Windows 8 already comes with a letter recognizer out of the box.  Alternatively, you can use manipulation events for letter recognition, which I discuss below.  Let's begin!

Referring to my Windows 8 blog, we see that all custom gestures are simply handled with the use of manipulation events. Simply specifying the manipulation event handler names in XAML (or code-behind) then implementing the handlers in the code behind suffices.  Unlike the iOS side, we don't need to subclass and override a set of parent functions.

When comparing letter recognition implementation code between my iOS and Windows 8 samples, essentially, I used the exact variable declarations and handler logic for both; there was no necessity to change the logic and flow of my design.  This made letter recognition pretty easy.  There is a slight change for the variable names (eg: CGFloat for iOS, float for Windows 8).  Also, the Windows 8 side didn't necessitate overriding the reset routine of iOS.

Here is a simple table of the syntactic differences that I encountered for coding project (refer to my Windows 8 blog above for more details on the elements used):

iOS syntax

Windows 8 syntax


(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

void manip_delta(object sender, ManipulationDeltaRoutedEventArgs e)

manip_delta is name of function that I used on Windows 8 side. Clearly, different method declaration structure

    [super touchesMoved:touches withEvent:event];



For Windows 8, I'm not explicitly making a call to parent

[self distance:x1 second_point:xi]

distance(x1, xi)

iOS and Windows 8 syntax differ when calling declared functions (and the function names are thus different!)



Different absolute value API usage; a minor change

 That's it!  Thanks for reading!  Feel free to comment with questions, ideas, etc.


Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.