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 ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.