Forum Xamarin.Forms

Problem to create a touch plugin

RobertoFonsecaRobertoFonseca BRMember
edited October 2015 in Xamarin.Forms

I'm trying to create a plugin to use touch events in forms.

I'll use iOS as exemple, so i've created the classes, ViewTouch and CrossTouch extended to UIView and Interface respectively

public class ViewTouch : UIView { //The overridden methods here! }

public class CrossTouch : ITouch { //The implementation and others here. }

On the interface I created a single event which is called everytime the overridden touch methods on ViewTouch is executed.

public interface ITouch
{
      event EventHandler<EventArgs> TouchChanged;
}

On iOS library I use the Init() method to get the UIView from AppDelegate;
CrossTouch.Init (UIApplication.SharedApplication.KeyWindow.RootViewController.View);

The problem is "How I get the UIView from iOS?" (or maybe the UIViewController), cause the View on init is null.

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    What does CrossTouch.Init do? It's not clear to me what the relationship is between your ViewTouch class (a view) and the view passed in to CrossTouch.Init.

    The RootViewController (and the KeyWindow for that matter) will be created in base.FinishedLaunching. The FormsApplicationDelegate class handles that for you. So you would have to put this line after calling base.

Sign In or Register to comment.