* 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
This commit is contained in:
2020-05-05 01:53:33 +08:00
parent e7fbee8d41
commit 66f0c1ba1b
14 changed files with 536 additions and 30 deletions

View File

@ -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);
}
}
}
}
}

View File

@ -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<Image> 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;
}
}
}
}

View File

@ -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<Label> e)
{
base.OnElementChanged(e);
if (Control != null && Element is RoundLabel label)
{
int radius = label.CornerRadius;
if (radius > 0)
{
Control.Layer.CornerRadius = radius;
Control.BackgroundColor = label.BackgroundColor.ToUIColor();
Control.Layer.MasksToBounds = true;
}
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == RoundLabel.CornerRadiusProperty.PropertyName)
{
if (Control != null && Element is RoundLabel label)
{
int radius = label.CornerRadius;
if (radius > 0)
{
Control.Layer.CornerRadius = radius;
Control.BackgroundColor = label.BackgroundColor.ToUIColor();
Control.Layer.MasksToBounds = true;
}
}
}
}
}
}