Exemple #1
0
        public void RemoveObjectAtIndex(int index,GridViewItemAnimation animation)
        {
            Debug.Assert((index >= 0 && index < numberTotalItems), "Invalid index specified");

            GridViewCell cell = CellForItemAtIndex(index);

            for (int i = index + 1; i < numberTotalItems; i++)
            {
                GridViewCell oldView = CellForItemAtIndex(i);
                oldView.Tag = oldView.Tag - 1;
            }

            if (cell!=null)
                cell.Tag = kTagOffset - 1;
            numberTotalItems--;

            bool shouldScroll = animation.HasFlag(GridViewItemAnimation.Scroll);
            bool animate = animation.HasFlag(GridViewItemAnimation.Fade);
            //bool shouldScroll = animation == GridViewItemAnimation.Scroll;
            //bool animate = animation == GridViewItemAnimation.Fade;

            UIView.Animate(animate ? kDefaultAnimationDuration : 0.0f,0,kDefaultAnimationOptions,
            delegate
            {
                if (cell!=null)
                {
                    cell.ContentView.Alpha = 0.3f;
                    cell.Alpha = 0.0f;
                }

                if (shouldScroll)
                {
                    ScrollToObjectAtIndex(index,GridViewScrollPosition.None,animate);
                }
                RecomputeSizeAnimated((animation != GridViewItemAnimation.None));
            },
            delegate
            {
                if (cell!=null)
                    cell.ContentView.Alpha = 1.0f;
                QueueReusableCell(cell);
                if (cell!=null)
                    cell.RemoveFromSuperview();

                firstPositionLoaded = lastPositionLoaded = GMGV_INVALID_POSITION;
                LoadRequiredItems();
                RelayoutItemsAnimated(animate);
            });

            SetSubviewsCacheAsInvalid();
        }
Exemple #2
0
        public void ReloadObjectAtIndex(int index,GridViewItemAnimation animation)
        {
            Debug.Assert((index >= 0 && index < numberTotalItems), "Invalid index");

            UIView currentView = CellForItemAtIndex(index);

            if (currentView==null)
                return;

            GridViewCell cell = NewItemSubViewForPosition(index);
            PointF origin = layoutStrategy.OriginForItemAtPosition(index);
            cell.Frame = new RectangleF(origin.X, origin.Y, itemSize.Width, itemSize.Height);
            cell.Alpha = 0;
            AddSubview(cell);

            currentView.Tag = kTagOffset - 1;
            bool shouldScroll = animation.HasFlag(GridViewItemAnimation.Scroll);
            bool animate = animation.HasFlag(GridViewItemAnimation.Fade);
            UIView.Animate(animate ? kDefaultAnimationDuration : 0.0,0.0,kDefaultAnimationOptions,
            delegate
            {
                if (shouldScroll)
                {
                    ScrollToObjectAtIndex(index,GridViewScrollPosition.None,false);
                }
                currentView.Alpha = 0;
                cell.Alpha = 1;
            },
            delegate
            {
                currentView.RemoveFromSuperview();
            });

            SetSubviewsCacheAsInvalid();
        }
Exemple #3
0
        public void InsertObjectAtIndex(int index,GridViewItemAnimation animation)
        {
            Debug.Assert((index >= 0 && index <= numberTotalItems), "Invalid index specified");

            GridViewCell cell = null;

            if (index >= firstPositionLoaded && index <= lastPositionLoaded)
            {
                cell = NewItemSubViewForPosition(index);

                for (int i = numberTotalItems - 1; i >= index; i--)
                {
                    UIView oldView = CellForItemAtIndex(i);
                    oldView.Tag = oldView.Tag + 1;
                }

                if (animation == GridViewItemAnimation.Fade)
                {
                    cell.Alpha = 0;
                    UIView.BeginAnimations(null);
                    UIView.SetAnimationDelay(kDefaultAnimationDuration);
                    UIView.SetAnimationDuration(kDefaultAnimationDuration);
                    cell.Alpha = 1.0f;
                    UIView.CommitAnimations();
                }
                AddSubview(cell);
            }

            numberTotalItems++;
            RecomputeSizeAnimated(animation!=GridViewItemAnimation.None);

            bool shouldScroll = animation.HasFlag(GridViewItemAnimation.Scroll);
            if (shouldScroll)
            {
                UIView.Animate (kDefaultAnimationDuration,0,kDefaultAnimationOptions,
                delegate
                {
                    ScrollToObjectAtIndex(index,GridViewScrollPosition.None,false);
                },
                delegate
                {
                    LayoutSubviewsWithAnimation(animation);
                });
            }
            else
            {
                LayoutSubviewsWithAnimation(animation);
            }

            SetSubviewsCacheAsInvalid();
        }
Exemple #4
0
 public void LayoutSubviewsWithAnimation(GridViewItemAnimation animation)
 {
     RecomputeSizeAnimated(animation!=GridViewItemAnimation.None);
         //!(animation & GMGridViewItemAnimation.None));
     RelayoutItemsAnimated(animation==GridViewItemAnimation.Fade);  // only supported animation for now
     LoadRequiredItems();
 }
Exemple #5
0
        public void SwapObjectAtIndex(int index1,int index2,GridViewItemAnimation animation)
        {
            Debug.Assert((index1 >= 0 && index1 < numberTotalItems), "Invalid index1 specified");
            Debug.Assert((index2 >= 0 && index2 < numberTotalItems), "Invalid index2 specified");

            GridViewCell view1 = CellForItemAtIndex(index1);
            GridViewCell view2 = CellForItemAtIndex(index2);

            view1.Tag = index2 + kTagOffset;
            view2.Tag = index1 + kTagOffset;

            PointF view1Origin = layoutStrategy.OriginForItemAtPosition(index2);
            PointF view2Origin = layoutStrategy.OriginForItemAtPosition(index1);

            view1.Frame = new RectangleF(view1Origin.X, view1Origin.Y, itemSize.Width, itemSize.Height);
            view2.Frame = new RectangleF(view2Origin.X, view2Origin.Y, itemSize.Width, itemSize.Height);

            RectangleF visibleRect = new RectangleF(ContentOffset.X,
                                                    ContentOffset.Y,
                                                    ContentSize.Width,
                                                    ContentSize.Height);

            // Better performance animating ourselves instead of using animated:YES in scrollRectToVisible
            bool shouldScroll = animation.HasFlag(GridViewItemAnimation.Scroll);
            UIView.Animate(kDefaultAnimationDuration,0,kDefaultAnimationOptions,
            delegate
            {
                if (shouldScroll)
                {
                    if (!CGRectIntersectsRect(view2.Frame, visibleRect))
                    {
                        ScrollToObjectAtIndex(index1,GridViewScrollPosition.None,false);
                    }
                    else if (!CGRectIntersectsRect(view1.Frame, visibleRect))
                    {
                        ScrollToObjectAtIndex(index2,GridViewScrollPosition.None,false);
                    }
                }
            },
            delegate
            {
                SetNeedsLayout();
            });
        }