【问题标题】:Xamarin iOS Setting NavigationController.NavigationBar.Translucent = true; shifts scrollview content upwordsXamarin iOS 设置 NavigationController.NavigationBar.Translucent = true;将滚动视图内容向上移动
【发布时间】:2018-11-27 07:44:13
【问题描述】:

当用户在屏幕上滚动时,我想逐渐在屏幕上显示导航栏。并想让它隐藏导航栏(设置 Alpha,因为我想显示导航控制器的后退箭头)。

向上滚动时很好。

但是当我将滚动视图设置在初始位置时,如果我将其半透明属性设置为 true,即 NavigationController.NavigationBar.Translucent = true; 然后它以相同的导航栏高度将内容向上移动。

预期结果:滚动完成后,滚动视图应处于初始状态。

谁能帮我解决这个问题?

【问题讨论】:

    标签: ios xamarin scrollview


    【解决方案1】:

    如果您在 iOS 10 上启用了 AutomaticallyAdjustsScrollViewInsets 或在 iOS 11 上启用了 ContentInsetAdjustmentBehavior 并且您为滚动视图添加了正确的约束。滚动视图将自动调整其插图以使内容显示在 NavigationBar 下。

    但是如果你设置NavigationController.NavigationBar.Translucent = true; 并使用MyScrollView.SetContentOffset(new CGPoint(0, 0), true); 在初始位置设置滚动视图。这将导致您的问题:内容似乎被导航栏覆盖。

    您可以使用另一个 api 使滚动视图滚动到顶部:

    MyScrollView.ScrollRectToVisible(new CGRect(0, 0, 5, 5), true);
    

    这会将滚动视图的内容放置在导航栏下方。或者尝试判断Translucent的状态,如果是真的就用这个找回初始的地方:

    MyScrollView.SetContentOffset(new CGPoint(0, -NavigationController.NavigationBar.Frame.GetMaxY()), true);
    

    【讨论】:

    • 你是冠军兄弟?
    猜你喜欢
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 2017-10-05
    • 2017-10-05
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    相关资源
    最近更新 更多