Xamarin iOS large tittle scroll velocity snapping issue

222 Views Asked by At

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. My problem is outlined on this question: 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.

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. View.Superview is null for this page and would not allow me to change those constraints.

I have tried all sorts of different combinations of settings.

I have tried changing my ScrollView to a 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.

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. Is this possible on Xamarin? I haven't found a way to use UITableViewController when designing the UI in Xaml. Even if I can change to a UITableViewController, will I be able to set the constraints correctly in the renderer?

Are there any other things I should try?

Thank you for any responses.

1

There are 1 best solutions below

5
On

Try to find the ScrollView and change its constraints .

[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