コード例 #1
0
        private void adjustHeight()
        {
            double height;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                height = nonScrollableContentHeight + ScrollViewContent.Bounds.Height;
                if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    height += UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Bottom;
                }
            }
            else
            {
                var errorHeight = ErrorView.Hidden
                    ? 0
                    : ErrorView.SizeThatFits(UIView.UILayoutFittingCompressedSize).Height;
                var titleHeight      = DescriptionView.SizeThatFits(UIView.UILayoutFittingCompressedSize).Height;
                var isBillableHeight = BillableView.Hidden ? 0 : 56;
                var timeFieldsHeight = ViewModel.IsEditingGroup ? 0 : 167;
                height = preferredIpadHeight + errorHeight + titleHeight + timeFieldsHeight + isBillableHeight;
            }
            var newSize = new CGSize(0, height);

            if (newSize != PreferredContentSize)
            {
                PreferredContentSize = newSize;
                PresentationController.ContainerViewWillLayoutSubviews();
            }
            ScrollView.ScrollEnabled = ScrollViewContent.Bounds.Height > ScrollView.Bounds.Height;
        }
コード例 #2
0
        private void adjustHeight()
        {
            double height;
            nfloat coveredByKeyboard = 0;

            if (TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Compact)
            {
                height  = nonScrollableContentHeight + ScrollViewContent.Bounds.Height;
                height += UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Bottom;
            }
            else
            {
                var errorHeight = ErrorView.Hidden
                    ? 0
                    : ErrorView.SizeThatFits(UIView.UILayoutFittingCompressedSize).Height;
                var titleHeight      = DescriptionView.SizeThatFits(UIView.UILayoutFittingCompressedSize).Height;
                var isBillableHeight = BillableView.Hidden ? 0 : 56;
                var timeFieldsHeight = ViewModel.IsEditingGroup ? 0 : 167;
                height = preferredIpadHeight + errorHeight + titleHeight + timeFieldsHeight + isBillableHeight;
            }

            var newSize = new CGSize(0, height);

            if (newSize != PreferredContentSize)
            {
                PreferredContentSize = newSize;
                PresentationController.ContainerViewWillLayoutSubviews();
            }

            ScrollView.ScrollEnabled = ScrollViewContent.Bounds.Height > ScrollView.Bounds.Height;

            if (TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular)
            {
                if (ScrollView.ScrollEnabled && keyboardHeight > 0)
                {
                    nfloat scrollViewContentBottomPadding = ViewModel.IsEditingGroup ? coveredByKeyboard : 0;
                    ScrollView.ContentSize = new CGSize(ScrollView.ContentSize.Width, ScrollViewContent.Bounds.Height + scrollViewContentBottomPadding);
                    ScrollView.SetContentOffset(new CGPoint(0, ScrollView.ContentSize.Height - ScrollView.Bounds.Height), false);
                }
                else
                {
                    ScrollView.ContentSize = new CGSize(ScrollView.ContentSize.Width, ScrollViewContent.Bounds.Height);
                }
            }
        }
コード例 #3
0
        private void adjustHeight()
        {
            double height;
            nfloat coveredByKeyboard = 0;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                height = nonScrollableContentHeight + ScrollViewContent.Bounds.Height;
                if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    height += UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Bottom;
                }

                if (keyboardHeight > 0)
                {
                    // this bit of code depends on the knowledge of the component tree:
                    // - description label is inside of a container view which is placed in a stack view
                    // - we want to know the vertical location of the container view in the whole view
                    // - we actually want to know the Y coordinate of the bottom of the container and make
                    //   sure we don't overaly it with the keyboard
                    var container                   = DescriptionTextView.Superview;
                    var absoluteLocation            = View.ConvertPointFromView(container.Frame.Location, container.Superview.Superview);
                    var minimumVisibleContentHeight = View.Frame.Height - absoluteLocation.Y - container.Frame.Height;

                    coveredByKeyboard = keyboardHeight - minimumVisibleContentHeight;

                    var safeAreaOffset = UIDevice.CurrentDevice.CheckSystemVersion(11, 0)
                        ? Math.Max(UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Top, UIApplication.SharedApplication.StatusBarFrame.Height)
                        : 0;
                    var distanceFromTop = Math.Max(safeAreaOffset, View.Frame.Y - coveredByKeyboard);

                    height = UIScreen.MainScreen.Bounds.Height - distanceFromTop;
                }
            }
            else
            {
                var errorHeight = ErrorView.Hidden
                    ? 0
                    : ErrorView.SizeThatFits(UIView.UILayoutFittingCompressedSize).Height;
                var titleHeight      = DescriptionView.SizeThatFits(UIView.UILayoutFittingCompressedSize).Height;
                var isBillableHeight = BillableView.Hidden ? 0 : 56;
                var timeFieldsHeight = ViewModel.IsEditingGroup ? 0 : 167;
                height = preferredIpadHeight + errorHeight + titleHeight + timeFieldsHeight + isBillableHeight;
            }

            var newSize = new CGSize(0, height);

            if (newSize != PreferredContentSize)
            {
                PreferredContentSize = newSize;
                PresentationController.ContainerViewWillLayoutSubviews();
            }

            ScrollView.ScrollEnabled = ScrollViewContent.Bounds.Height > ScrollView.Bounds.Height;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                if (ScrollView.ScrollEnabled && keyboardHeight > 0)
                {
                    nfloat scrollViewContentBottomPadding = ViewModel.IsEditingGroup ? coveredByKeyboard : 0;
                    ScrollView.ContentSize = new CGSize(ScrollView.ContentSize.Width, ScrollViewContent.Bounds.Height + scrollViewContentBottomPadding);
                    ScrollView.SetContentOffset(new CGPoint(0, ScrollView.ContentSize.Height - ScrollView.Bounds.Height), false);
                }
                else
                {
                    ScrollView.ContentSize = new CGSize(ScrollView.ContentSize.Width, ScrollViewContent.Bounds.Height);
                }
            }
        }