17.9 C
London
Tuesday, September 3, 2024

Xamarin iOS Mission When Rotating Panorama some merchandise information will not be displaying


I am encountering a problem with my view controller that offers with dates and climate temperature information. After I rotate the gadget to panorama mode, a few of the climate merchandise information fails to show, whereas others are nonetheless seen.

This is how the view appears to be like like once I rotate to portrait to panorama.

enter image description here

Any suggestion or assist would just about appreaciated.

I’ve tried just a few issues to repair the problem with some objects not displaying up within the assortment view. I tinkered with the grid merchandise dimension and even eliminated the grid set for panorama mode, however sadly, I am nonetheless dealing with the identical drawback. It is unusual as a result of the info is being fetched appropriately, and I can see all of it nice within the console logs. What’s actually puzzling is that all the things shows completely when the app begins in panorama mode; it is solely after I rotate to panorama that some objects go lacking. I am stumped!

ViewWillTransitionToSize methodology

    public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) {
            base.ViewWillTransitionToSize(toSize, coordinator);

            coordinator.AnimateAlongsideTransition(context => {
                AddDateHeaders();
                UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
                if (orientation.IsLandscape()) {
                    // Calculate the accessible top for the gathering view
                    float availableHeight = (float)(CalCollectionView.Body.Peak - HeaderScrollView.Body.Peak);

                    grid = new UICollectionViewFlowLayout() {
                        ItemSize = new CGSize(200.0f, availableHeight / 2.2f),
                        SectionInset = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f),
                        ScrollDirection = UICollectionViewScrollDirection.Horizontal,
                        MinimumInteritemSpacing = 0,
                        MinimumLineSpacing = 2
                    };
                } else {
                    grid = new UICollectionViewFlowLayout() {
                        ItemSize = new CGSize(200.0f, (nfloat)(toSize.Peak / 2.35)),
                        SectionInset = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f),
                        ScrollDirection = UICollectionViewScrollDirection.Horizontal,
                        MinimumInteritemSpacing = 0,
                        MinimumLineSpacing = 2
                    };
                }

                SetupCollectionView();
                CalCollectionView.ReloadData();
                CalCollectionView.CollectionViewLayout.InvalidateLayout();
            }, completion: null);
        }

Entire code: CViewController.cs

namespace test-project.iOS {
    [MvxSidebarPresentation(MvxPanelEnum.Center, MvxPanelHintType.PushPanel, true)]
    public partial class CViewController : BController<CViewModel> {
        UICollectionViewFlowLayout grid;
        public CViewController() : base(nameof(CViewController)) {

        }

        public override void ViewWillAppear(bool animated) {

            base.ViewWillAppear(animated);
        }

        public override void ViewWillDisappear(bool animated) {

            base.ViewWillDisappear(animated);
        }

        public override void ViewDidLoad() {
            base.ViewDidLoad();
            SetupFlowLayout();
            SetupCollectionView();
            HeaderScrollView.Scrolled += (object sender, EventArgs e) => {
                CalCollectionView.ContentOffset = HeaderScrollView.ContentOffset;
            };

            CalCollectionView.Scrolled += (object sender, EventArgs e) => {
                HeaderScrollView.ContentOffset = CalCollectionView.ContentOffset;
            };

        }

        public override void DidReceiveMemoryWarning() {
            base.DidReceiveMemoryWarning();
        }

        public override void ViewDidAppear(bool animated) {
            base.ViewDidAppear(animated);

            ViewModel.CalendarReadyItem += (object sender, EventArgs args) => {
                InvokeOnMainThread(() => {
                    AddDateHeaders();
                    CalCollectionView.ReloadData();
                });
            };
        }

        void AddDateHeaders() {
            float labelWidth = 202.0f;
            float totalWidth = 0;
            foreach (var subview in HeaderScrollView.Subviews)
                subview.RemoveFromSuperview();

            for (int i = 0; i < ViewModel.dataService.DataDailyDates.Rely; i++)  UIViewAutoresizing.FlexibleWidth;
                dLabel.ClipsToBounds = true;
                dLabel.Textual content = mDate;
                dLabel.Traces = 2;
                dLabel.TextColor = UIColor.Black;
                dLabel.BackgroundColor = UIColor.White;

                HeaderScrollView.AddSubview(dLabel);
                totalWidth += labelWidth;
            

            // Regulate the content material inset to eradicate black area earlier than the primary date label
            float contentInset = ((float)HeaderScrollView.Bounds.Width - totalWidth) / 2;
            HeaderScrollView.ContentInset = new UIEdgeInsets(0, contentInset, 0, contentInset);

            // Set the content material dimension to the entire width of all date labels
            HeaderScrollView.ContentSize = new CGSize(totalWidth, 44);
        }






        void SetupFlowLayout() {
            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
            if (orientation.IsPortrait()) {
                grid = new UICollectionViewFlowLayout() {
                    ItemSize = new CGSize(200.0f, (CalCollectionView.Body.Peak / 2) + 12),
                    SectionInset = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f),
                    ScrollDirection = UICollectionViewScrollDirection.Horizontal,
                    MinimumInteritemSpacing = 0,
                    MinimumLineSpacing = 2
                };
            } else {

                grid = new UICollectionViewFlowLayout() {
                    ItemSize = new CGSize(200.0f, (CalCollectionView.Body.Peak / 4.8)),
                    SectionInset = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f),
                    ScrollDirection = UICollectionViewScrollDirection.Horizontal,
                    MinimumInteritemSpacing = 0,
                    MinimumLineSpacing = 2
                };
            }

        }

        void SetupCollectionView() {
            CalCollectionView.CollectionViewLayout = grid;
            CalCollectionView.RegisterClassForCell(typeof(DayCell), DayCell.Key);
            CalCollectionView.DataSource = new MySource(ViewModel);
        }


        public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) {
            base.ViewWillTransitionToSize(toSize, coordinator);

            coordinator.AnimateAlongsideTransition(context => {
                AddDateHeaders();
                UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;
                if (orientation.IsLandscape()) {
                    // Calculate the accessible top for the gathering view
                    float availableHeight = (float)(CalCollectionView.Body.Peak - HeaderScrollView.Body.Peak);

                    // Create a brand new circulation format with an merchandise dimension based mostly on the accessible top
                    grid = new UICollectionViewFlowLayout() {
                        ItemSize = new CGSize(200.0f, availableHeight / 2.2f),
                        SectionInset = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f),
                        ScrollDirection = UICollectionViewScrollDirection.Horizontal,
                        MinimumInteritemSpacing = 0,
                        MinimumLineSpacing = 2
                    };
                } else {
                    // Calculate the merchandise dimension based mostly on the peak of the view
                    grid = new UICollectionViewFlowLayout() {
                        ItemSize = new CGSize(200.0f, (nfloat)(toSize.Peak / 2.35)),
                        SectionInset = new UIEdgeInsets(0.0f, 0.0f, 0.0f, 0.0f),
                        ScrollDirection = UICollectionViewScrollDirection.Horizontal,
                        MinimumInteritemSpacing = 0,
                        MinimumLineSpacing = 2
                    };
                }

                // Set the up to date grid format to the gathering view
                SetupCollectionView();

                // Replace format based mostly on gadget orientation
                CalCollectionView.ReloadData();
                CalCollectionView.CollectionViewLayout.InvalidateLayout();
            }, completion: null);
        }
    }

    class MySource : UICollectionViewDataSource {
        CalViewModel ViewModel;

        public MySource(CalViewModel viewModel) {
            ViewModel = viewModel;
        }

        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) {
            var cell = collectionView.DequeueReusableCell(DayCell.Key, indexPath) as DayCell;

            cell.SetTextColors(indexPath.Merchandise % 2 == 0);
            cell.SetGradient(indexPath.Merchandise % 2 == 0);

            cell.ProbabilityLabel.Textual content = ViewModel.GetProbabilityText((int)indexPath.Merchandise);
            cell.WindsLabel.Textual content = ViewModel.GetWinds((int)indexPath.Merchandise);
            cell.ProbabilityDescriptionLabel.Textual content = ViewModel.GetProbabilityDescriptionText((int)indexPath.Merchandise);
            cell.PrecipImageView.Picture = UIImage.FromBundle(ViewModel.GetIconName((int)indexPath.Merchandise));
            cell.AirTempLabel.Textual content = ViewModel.GetAirTemp((int)indexPath.Merchandise);
            cell.PrecipLabel.Textual content = ViewModel.GetPrecip((int)indexPath.Merchandise);

            return cell;
        }

        public override nint GetItemsCount(UICollectionView collectionView, nint part) {
            attempt {
                return ViewModel.dataService.DataDailyDates.Rely * 2;
            } catch (Exception e) {
                return 0;
            }
        }

        public override nint NumberOfSections(UICollectionView collectionView) {
            return 1;
        }
    }
}

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here