【问题标题】:Xamarin iOS large tittle scroll velocity snapping issueXamarin iOS 大标题滚动速度捕捉问题
【发布时间】:2022-01-22 04:45:52
【问题描述】:

我正在使用 Xamarin.Forms 5.0 版开发适用于 iOS 15 的应用程序。我正在努力平滑大标题滚动过渡。在这个问题上概述了我的问题:iOS 11 large navigation bar title unexpected velocity

根据上面的链接,这在 Swift 上似乎是一个相当简单的解决方案,但我正在努力使用 Xamarin.iOS 来做到这一点。

使用自定义渲染器,我有以下设置:

ExtendedLayoutIncludesOpaqueBars = True;
EdgesForExtendedLayout = UIRectEdge.Top;
AutomaticallyAdjustsScrollViewInsets = true;
NavigationController.NavigationBar.PrefersLargeTitles = true;
NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Automatic;
NavigationController.NavigationBar.Translucent = true;

我尝试通过将 ScrollView 的约束设置为 View 的约束来修改它们。此页面的 View.Superview 为空,不允许我更改这些约束。

我尝试了各种不同的设置组合。

我尝试将我的 ScrollView 更改为 TableView。

我知道我可以制作一个自定义导航栏来模拟这种转换,但我正在尝试使用原生 iOS 设置和 UI 设计。

this 问题的一个答案表明,获得平滑滚动过渡的唯一方法是使用 UITableViewController 而不是内部带有 UITableView 的 UIViewController。这可能在 Xamarin 上吗?在 Xaml 中设计 UI 时,我还没有找到使用 UITableViewController 的方法。即使我可以更改为 UITableViewController,我是否能够在渲染器中正确设置约束?

还有什么我应该尝试的吗?

感谢您的任何回复。

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: ios user-interface xamarin xamarin.ios large-title


【解决方案1】:

尝试找到 ScrollView 并更改其约束。

[assembly: ExportRenderer(typeof(ContentPage), typeof(MyBarRenderer))]
namespace FormsApp.iOS
{
    internal class MyBarRenderer : PageRenderer
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ExtendedLayoutIncludesOpaqueBars = true;

            foreach (UIView view in View.Subviews)
            {
                if (view is UIScrollView sc)
                {
                    NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[] {
                        sc.TopAnchor.ConstraintEqualTo(View.TopAnchor),
                        sc.LeftAnchor.ConstraintEqualTo(View.LeftAnchor),
                        sc.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),
                        sc.RightAnchor.ConstraintEqualTo(View.RightAnchor),
                    });
                }
            }
        }
    }
}

参考

iOS 11 large title navigation bar snaps instead of smooth transition

【讨论】:

猜你喜欢
  • 2021-12-04
  • 1970-01-01
  • 1970-01-01
  • 2023-02-02
  • 2011-05-15
  • 2022-01-26
  • 1970-01-01
  • 1970-01-01
  • 2018-07-23
相关资源
最近更新 更多