Book Image

iOS Development using MonoTouch Cookbook

By : Dimitris Tavlikos
Book Image

iOS Development using MonoTouch Cookbook

By: Dimitris Tavlikos

Overview of this book

<p>MonoTouch brings the amazing revenue opportunities of Apple’s billion dollar app store to C# and .NET developers. <br /><br />This cookbook leaves no stone unturned, providing you with practical recipes covering user interfaces, data management, multimedia , web services, and localization, right through to application deployment on the app store.<br /><br />Whatever the area of MonoTouch iOS development you need to know about, you will find a recipe for it in this cookbook. Minimum theory and maximum practical action defines this book. It is jam packed with recipes for interacting with the device hardware, like the GPS, compass and the accelerometer. Recipes for those all important real world issues such as designing the UI with the integrated designer introduced with Xcode 4. It is the essential cookbook for C# and .NET developers wanting to be part of the exciting and lucrative world of iOS development.</p>
Table of Contents (22 chapters)
iOS Development Using MonoTouch Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

A simple drawing application


In this recipe, we will use the techniques that we learned to create a drawing application.

Getting ready

Create a new project in MonoDevelop, and name it FingerDrawingApp. Once again, we will need a custom view. Add a class deriving from UIView, and name it CanvasView.

How to do it...

  1. Implement the CanvasView class with the following code:

    public class CanvasView : UIView{
      public CanvasView (RectangleF frame) : base(frame){
        this.drawPath = new CGPath();
      }
      private PointF touchLocation;
      private PointF previousTouchLocation;
      private CGPath drawPath;
      private bool fingerDraw;
      public override void TouchesBegan (NSSet touches, UIEvent evt){
        base.TouchesBegan (touches, evt);
        UITouch touch = touches.AnyObject as UITouch;
        this.fingerDraw = true;
        this.touchLocation = touch.LocationInView(this);
        this.previousTouchLocation = touch.PreviousLocationInView(this);
        this.SetNeedsDisplay();
      }
      public override void TouchesMoved (NSSet touches...