Building a VisualElementRenderer for iOS
To handle native touch events on iOS, we are going to build a VisualElementRenderer
. These work similar to CustomRenderers, but instead of rendering and replacing the entire control, we are able to render specific attributes, so we are able to attach native attributes to a Xamarin.Forms
view.
Let's start with adding a new folder inside the Renderers
folder called FocusView
. Add in a new file called FocusViewRendererTouchAttribute.cs
and implement the following:
public class FocusViewRendererTouchAttribute : VisualElementRenderer<FocusView> { public override void TouchesBegan (NSSet touches, UIEvent evt) { base.TouchesBegan (touches, evt); FocusView focusView = ((FocusView)this.Element); UITouch touch = touches.AnyObject as UITouch; if (touch != null) { var posc = touch.LocationInView (touch.View); focusView.NotifyFocus...