c# - 在 iOS 上将自定义呈现的页面移动到状态栏下方

标签 c# ios xamarin xamarin.forms nsviewcontroller

为了将我的应用程序页面定位在 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/

相关文章:

c# - Entity Framework 5.0 - 1 对 1 关系无故为 NULL

iphone - 获取字符串的语言

android - 绝对元素在纵向模式手机中没有响应

ios - 命名空间中不存在类型或命名空间名称 "MyBindingLib"(您是否缺少程序集引用?)

ios - 在钥匙串(keychain)中找不到有效的 iPhone 代码签名 key

c# - 多线程windows phone应用程序

c# - Winforms Devexpress 应用部署

适用于 Android 的 Xamarin Tesseract OCR 绑定(bind)

c# - 无法获取结构 C# 的指针

ios - 如何将本应由位置服务启动的 iPhone 应用程序从终止状态调试到后台?