简体   繁体   English

Xamarin iOS 大标题滚动速度捕捉问题

[英]Xamarin iOS large tittle scroll velocity snapping issue

I am using Xamarin.Forms version 5.0 to develop an app for iOS 15. I am struggling to smooth the large title scroll transition.我正在使用 Xamarin.Forms 5.0 版为 iOS 15 开发应用程序。我正在努力平滑大标题滚动过渡。 My problem is outlined on this question: iOS 11 large navigation bar title unexpected velocity这个问题概述了我的问题: iOS 11 large navigation bar title unexpected velocity

According to the above link, It seems like a fairly simple solution on Swift but I am struggling to do this using Xamarin.iOS.根据上面的链接,在 Swift 上似乎是一个相当简单的解决方案,但我正在努力使用 Xamarin.iOS 来做到这一点。

Using a custom renderer, I have the following settings:使用自定义渲染器,我有以下设置:

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

I have tried modifying the constraints of my ScrollView by setting them to the constraints of the View.我尝试通过将 ScrollView 的约束设置为 View 的约束来修改它们。 View.Superview is null for this page and would not allow me to change those constraints. View.Superview 是此页面的 null 并且不允许我更改这些约束。

I have tried all sorts of different combinations of settings.我尝试了各种不同的设置组合。

I have tried changing my ScrollView to a TableView.我尝试将 ScrollView 更改为 TableView。

I know I could make a custom navigation bar that could simulate this transition but I am trying to use native iOS settings and UI designs.我知道我可以制作一个自定义导航栏来模拟这种转换,但我正在尝试使用原生 iOS 设置和 UI 设计。

One of the answers on this question suggest the only way to get the smooth scroll transition is to use a UITableViewController instead of a UIViewController with a UITableView inside. 这个问题的答案之一表明获得平滑滚动转换的唯一方法是使用 UITableViewController 而不是 UIViewController 内部带有 UITableView。 Is this possible on Xamarin?这可能在 Xamarin 上吗? I haven't found a way to use UITableViewController when designing the UI in Xaml.在 Xaml 中设计 UI 时,我还没有找到使用 UITableViewController 的方法。 Even if I can change to a UITableViewController, will I be able to set the constraints correctly in the renderer?即使我可以更改为 UITableViewController,我能否在渲染器中正确设置约束?

Are there any other things I should try?还有什么我应该尝试的吗?

Thank you for any responses.感谢您的任何回复。

Try to find the ScrollView and change its constraints.尝试找到 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),
                    });
                }
            }
        }
    }
}

Refer to参考

iOS 11 large title navigation bar snaps instead of smooth transition iOS 11个大标题导航栏捕捉代替平滑过渡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM