From 66f0c1ba1b3a31a325d18e7f7a4362b7a9f93d40 Mon Sep 17 00:00:00 2001 From: Tsanie Lily Date: Tue, 5 May 2020 01:53:33 +0800 Subject: [PATCH] * Pixiview/UI/CircleUIs.cs: * Pixiview.iOS/Pixiview.iOS.csproj: * Pixiview.iOS/Renderers/RoundLabelRenderer.cs: * Pixiview.iOS/Renderers/CircleImageRenderer.cs: custom round corner controls * Pixiview/App.xaml: * Pixiview/Utils/Converters.cs: * Pixiview/GlobalSuppressions.cs: * Pixiview/UI/StyleDefinition.cs: * Pixiview/UI/AdaptedPage.cs: * Pixiview.iOS/Renderers/AdaptedPageRenderer.cs: observe orientation * Pixiview/MainPage.xaml: * Pixiview/Utils/Stores.cs: * Pixiview/MainPage.xaml.cs: * Pixiview/Utils/IllustData.cs: data and UI adjust --- Pixiview.iOS/Pixiview.iOS.csproj | 2 + Pixiview.iOS/Renderers/AdaptedPageRenderer.cs | 36 ++++ Pixiview.iOS/Renderers/CircleImageRenderer.cs | 31 ++++ Pixiview.iOS/Renderers/RoundLabelRenderer.cs | 47 ++++++ Pixiview/App.xaml | 1 + Pixiview/GlobalSuppressions.cs | 1 + Pixiview/MainPage.xaml | 59 ++++++- Pixiview/MainPage.xaml.cs | 154 +++++++++++++++++- Pixiview/UI/AdaptedPage.cs | 46 +++++- Pixiview/UI/CircleUIs.cs | 25 +++ Pixiview/UI/StyleDefinition.cs | 79 ++++++++- Pixiview/Utils/Converters.cs | 20 +++ Pixiview/Utils/IllustData.cs | 2 + Pixiview/Utils/Stores.cs | 63 +++++-- 14 files changed, 536 insertions(+), 30 deletions(-) create mode 100644 Pixiview.iOS/Renderers/CircleImageRenderer.cs create mode 100644 Pixiview.iOS/Renderers/RoundLabelRenderer.cs create mode 100644 Pixiview/UI/CircleUIs.cs create mode 100644 Pixiview/Utils/Converters.cs diff --git a/Pixiview.iOS/Pixiview.iOS.csproj b/Pixiview.iOS/Pixiview.iOS.csproj index a297a95..a188d5a 100644 --- a/Pixiview.iOS/Pixiview.iOS.csproj +++ b/Pixiview.iOS/Pixiview.iOS.csproj @@ -70,6 +70,8 @@ + + diff --git a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs index 248e127..c06fbd2 100644 --- a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs +++ b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using Foundation; using Pixiview.iOS.Renderers; using Pixiview.UI; using Pixiview.Utils; @@ -11,6 +12,9 @@ namespace Pixiview.iOS.Renderers { public class AdaptedPageRenderer : PageRenderer { + UIDeviceOrientation lastOrientation; + NSObject observer; + public override void ViewDidLoad() { base.ViewDidLoad(); @@ -30,6 +34,20 @@ namespace Pixiview.iOS.Renderers { SetStatusBarStyle(style); } + + observer = UIDevice.Notifications.ObserveOrientationDidChange(ChangeOrientation); + ChangeOrientation(null, null); + } + + public override void ViewWillDisappear(bool animated) + { + if (observer != null) + { + observer.Dispose(); + observer = null; + } + + base.ViewWillDisappear(animated); } private void SetStatusBarStyle(UIStatusBarStyle style) @@ -64,5 +82,23 @@ namespace Pixiview.iOS.Renderers return UIStatusBarStyle.Default; } } + + void ChangeOrientation(object sender, NSNotificationEventArgs e) + { + var current = UIDevice.CurrentDevice.Orientation; + if (current == UIDeviceOrientation.FaceUp || current == UIDeviceOrientation.FaceDown) + { + //current = UIDeviceOrientation.Portrait; + return; + } + if (lastOrientation != current) + { + lastOrientation = current; + if (Element is AdaptedPage page) + { + page.OnOrientationChanged((Orientation)lastOrientation); + } + } + } } } diff --git a/Pixiview.iOS/Renderers/CircleImageRenderer.cs b/Pixiview.iOS/Renderers/CircleImageRenderer.cs new file mode 100644 index 0000000..85f77a2 --- /dev/null +++ b/Pixiview.iOS/Renderers/CircleImageRenderer.cs @@ -0,0 +1,31 @@ +using Pixiview.iOS.Renderers; +using Pixiview.UI; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(CircleImage), typeof(CircleImageRenderer))] +namespace Pixiview.iOS.Renderers +{ + public class CircleImageRenderer : ImageRenderer + { + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + if (Control != null) + { + Control.Layer.MasksToBounds = true; + } + } + + public override void LayoutSubviews() + { + base.LayoutSubviews(); + + if (Control != null) + { + Control.Layer.CornerRadius = Control.Frame.Size.Width / 2; + } + } + } +} diff --git a/Pixiview.iOS/Renderers/RoundLabelRenderer.cs b/Pixiview.iOS/Renderers/RoundLabelRenderer.cs new file mode 100644 index 0000000..27f5fae --- /dev/null +++ b/Pixiview.iOS/Renderers/RoundLabelRenderer.cs @@ -0,0 +1,47 @@ +using System.ComponentModel; +using Pixiview.iOS.Renderers; +using Pixiview.UI; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(RoundLabel), typeof(RoundLabelRenderer))] +namespace Pixiview.iOS.Renderers +{ + public class RoundLabelRenderer : LabelRenderer + { + protected override void OnElementChanged(ElementChangedEventArgs