コード例 #1
0
        private void BringIntoView(int index, BringIntoViewMode mode)
        {
            if (index < 0 || index >= ItemsCount)
            {
                return;
            }

            Offset = CalcBringIntoViewOffset(index, mode, Viewport, Extent, Offset);

            _enqueueBringIntoViewRequest = null;
        }
コード例 #2
0
        private Vector CalcBringIntoViewOffset(int index, BringIntoViewMode mode, Size viewport, Size extent, Vector offset)
        {
            if (index < 0 || index >= ItemsCount)
            {
                return(offset);
            }

            var orientation      = Orientation;
            var orientedViewPort = viewport.AsOriented(orientation);
            var orientedExtent   = extent.AsOriented(orientation);
            var orientedOffset   = offset.AsOriented(orientation);
            var orientedViewer   = new OrientedScrollView(orientation, orientedViewPort.Direct, orientedExtent.Direct,
                                                          orientedOffset.Direct);

            orientedViewer.Offset = orientedViewer.Offset - index > 0.0 || mode == BringIntoViewMode.Top
                                ? index
                                : index - orientedViewer.Viewport + 1.0;

            orientedOffset.Direct = orientedViewer.Offset;

            return(orientedOffset.Vector);
        }
コード例 #3
0
        /// <summary>
        /// Make a view visible into a scroll view
        /// </summary>
        /// <param name="scrollView">The scroll view to scroll to get the item visible.</param>
        /// <param name="view">View to make visible.</param>
        /// <param name="mode">Specifies a mode to use to place the view into the view port.</param>
        /// <param name="padding">
        /// Add an extra margin to the view from the edge of the view port when mode is
        /// <seealso cref="BringIntoViewMode.TopLeftOfViewPort"/> or <seealso cref="BringIntoViewMode.BottomRightOfViewPort"/>.
        /// </param>
        /// <param name="animationMode">Specifies animation mode to use to animate the scrolling (or not).</param>
        public static void BringIntoView(
            this UIScrollView scrollView,
            UIView view,
            BringIntoViewMode mode      = BringIntoViewMode.ClosestEdge,
            int padding                 = 0,
            ScrollingMode animationMode = ScrollingMode.Forced)
        {
            var boundsOfViewInScrollViewCoordinatesSystem = scrollView.ConvertRectFromView(view.Bounds, view);
            var bounds   = scrollView.Bounds;
            var inset    = scrollView.ContentInset;
            var viewPort = new CGRect
                           (
                bounds.X + inset.Left,
                bounds.Y + inset.Top,
                bounds.Width - inset.Left - inset.Right,
                bounds.Height - inset.Top - inset.Bottom
                           );

            nfloat x, y;

            switch (mode)
            {
            case BringIntoViewMode.ClosestEdge:
                scrollView.ScrollRectToVisible(boundsOfViewInScrollViewCoordinatesSystem, animationMode != ScrollingMode.NotAnimated);
                return;

            case BringIntoViewMode.TopLeftOfViewPort:
                x = boundsOfViewInScrollViewCoordinatesSystem.Left - padding;
                y = boundsOfViewInScrollViewCoordinatesSystem.Top - padding;
                break;

            case BringIntoViewMode.CenterOfViewPort:
                x = boundsOfViewInScrollViewCoordinatesSystem.Left - (viewPort.Width / 2) + (boundsOfViewInScrollViewCoordinatesSystem.Width / 2);
                y = boundsOfViewInScrollViewCoordinatesSystem.Top - (viewPort.Height / 2) + (boundsOfViewInScrollViewCoordinatesSystem.Height / 2);
                break;

            case BringIntoViewMode.BottomRightOfViewPort:
                x = boundsOfViewInScrollViewCoordinatesSystem.Right - viewPort.Width + padding;
                y = boundsOfViewInScrollViewCoordinatesSystem.Bottom - viewPort.Height + padding;
                break;

            default:
                throw new NotSupportedException("Unknown scroll into view behavior");
            }

            var maxX = scrollView.ContentSize.Width - viewPort.Width;
            var maxY = scrollView.ContentSize.Height - viewPort.Height;

            x = (nfloat)Math.Max(0, (nfloat)Math.Min(maxX, x));
            y = (nfloat)Math.Max(0, (nfloat)Math.Min(maxY, y));

            switch (animationMode)
            {
            case ScrollingMode.NotAnimated:
                scrollView.SetContentOffset(new CGPoint(x, y), false);
                break;


            case ScrollingMode.Animated:
                scrollView.SetContentOffset(new CGPoint(x, y), true);
                break;

            case ScrollingMode.Forced:
                scrollView.ContentOffset = new CGPoint(x, y);
                break;

            default:
                throw new NotSupportedException("Unknown animation mode");
            }
        }
コード例 #4
0
ファイル: IItemsHost.cs プロジェクト: Egaros/lib
 protected BringIntoViewRequest(int index, BringIntoViewMode mode, int fallbackIndex)
 {
     Index         = index;
     Mode          = mode;
     FallbackIndex = fallbackIndex;
 }