Created
August 1, 2017 23:45
-
-
Save rdelrosario/b1abb918fa0d5c51cbcdf7189b53e7e4 to your computer and use it in GitHub Desktop.
Zoomable ScrollView iOS Renderer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ZoomableApp.iOS.Renderers; | |
using UIKit; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Platform.iOS; | |
using System.Linq; | |
[assembly: ExportRenderer(typeof(ScrollView), typeof(ZoomScrollViewRenderer))] | |
namespace ZoomableApp.iOS.Renderers | |
{ | |
public class ZoomScrollViewRenderer : ScrollViewRenderer | |
{ | |
// bool zoomEnabled = false; | |
protected override void OnElementChanged(VisualElementChangedEventArgs e) | |
{ | |
base.OnElementChanged(e); | |
MaximumZoomScale = 3f; | |
MinimumZoomScale = 1.0f; | |
} | |
public override void LayoutSubviews() | |
{ | |
base.LayoutSubviews(); | |
if(Subviews.Length > 0) | |
{ | |
ViewForZoomingInScrollView += GetViewForZooming; | |
} | |
else | |
{ | |
ViewForZoomingInScrollView -= GetViewForZooming; | |
} | |
} | |
public UIView GetViewForZooming(UIScrollView sv) | |
{ | |
return this.Subviews.FirstOrDefault(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment