I try to implement the following structure of views in my Xamarin.iOS application. I'm using FluentLayout and MvvmCross 6.0.1.
View (controller)
- UIScrollView
- UIView
- UIView,
- UIView/UILabel etc.
- UIView/UILabel etc.
- ...
I'd like the view to be scrollable, but unfortunately it is possible only the second time I navigate to this view. In other words you have to navigate back and navigate to the view again to be able to scroll this view.
The controller is inside the MvxBaseViewController i.e. the structure of controllers is like this:
- DashBoard (MvxTabBarViewController, WrapInNavigationController=true)
- Tab1 (MvxBaseViewController)
- Tab2 (MvxBaseViewController)
- Tab3 (MvxBaseViewController)
- The problematic view (MvxBaseViewController)
I was following this guide while setting up the constraints which are as follows:
var innerView = new UIView();
innerView.AddSubview(view1);
innerView.AddSubview(view2);
innerView.AddSubview(view3);
innerView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
innerView.AddConstraints(
view1.AtTopOf(innerView).Plus(21.0f),
view1.WithSameCenterX(innerView),
view1.WithSameWidth(innerView).WithMultiplier(0.8f),
view1.Height().EqualTo(44f),
view2.Below(view1).Plus(10.0f),
view2.WithSameCenterX(innerView),
view2.WithSameWidth(innerView).WithMultiplier(0.9f),
view2.Height().EqualTo(16.0f),
view3.Below(view2).Plus(21.0f),
view3.WithSameCenterX(innerView),
view3.WithSameWidth(innerView).WithMultiplier(0.9f),
view3.Height().EqualTo(40.0f),
);
var scrollView = new UIScrollView();
scrollView.ShowsHorizontalScrollIndicator = false;
scrollView.AddSubview(innerView);
scrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
scrollView.AddConstraints(
innerView.AtTopOf(scrollView, 0),
innerView.AtBottomOf(scrollView, 0),
innerView.AtLeadingOf(scrollView, 0),
innerView.AtTrailingOf(scrollView, 0)
);
//scrollView.DirectionalLockEnabled = true;
View.AddSubview(scrollView);
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
View.AddConstraints(
//scrollView.WithSameWidth(View),
//scrollView.WithSameHeight(View),
innerView.WithSameWidth(View),
innerView.WithSameHeight(View).SetPriority(250),
scrollView.AtTopOf(View, 0),
scrollView.AtBottomOf(View, 0),
scrollView.AtLeadingOf(View, 0),
scrollView.AtTrailingOf(View, 0)
);
I suspect that the problem is related to the constraints but I wasn't able to figure out what is wrong. Do you have any ideas how to solve this?