为了将我的应用程序页面定位在 iOS 状态栏下方,我为我的页面创建了一个自定义渲染器。它应该将页面移动到栏下方,就像下面的 XAML 所做的那样:
<local:CustomRenderedPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<OnPlatform.iOS>
0, 40, 0, 0
</OnPlatform.iOS>
</OnPlatform>
</local:CustomRenderedPage.Padding>
因此我使用了this我已将其转换为 C# 的答案。
但是,没有任何错误,页面仍然出现在状态栏后面。 为了检查自定义渲染器是否正常工作,我也更改了背景颜色,它正在工作。
//manually adjust the frame of the main view to prevent it from appearing under the status bar.
var app = UIApplication.SharedApplication;
if (!app.StatusBarHidden)
{
this.View.BackgroundColor = UIKit.UIColor.FromRGB(20, 100, 20); //works
this.View.Frame = new CoreGraphics.CGRect(0.0, app.StatusBarFrame.Size.Height, this.View.Bounds.Size.Width, this.View.Bounds.Size.Height - app.StatusBarFrame.Size.Height); // does not work
}
Log.WriteLine("Done"); // works
我是不是做错了什么,或者为什么这不起作用?
最佳答案
正如我之前所问的,您从何处调用此代码,您回答“从我的自定义页面渲染器内部”。但要点是你在渲染器中调用它的位置。 这是有效的代码。
[assembly: ExportRenderer(typeof(MainPage), typeof(MainPageRenderer))]
namespace ButtonRendererDemo.iOS
{
class MainPageRenderer : PageRenderer
{
public override void ViewWillAppear(bool animated)
{
View.Frame = new CoreGraphics.CGRect(View.Frame.X, View.Frame.Y + 100, View.Frame.Width, View.Frame.Height);
}
}
}
关于c# - 在 iOS 上将自定义呈现的页面移动到状态栏下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40062056/