MonoTouch.Dialog.CalendarMonthView.MoveCalendarMonths C# (CSharp) Method

MoveCalendarMonths() public method

public MoveCalendarMonths ( System.DateTime date, bool animated ) : void
date System.DateTime
animated bool
return void
        public void MoveCalendarMonths(DateTime date, bool animated)
        {
            bool upwards = false;
            if (date.Month == CurrentMonthYear.Month && date.Year == CurrentMonthYear.Year)
                animated = false; else if (date > CurrentMonthYear)
                upwards = true;
            CurrentMonthYear = new DateTime (date.Year, date.Month, 1);
            if (MonthChanged != null)
                MonthChanged (CurrentMonthYear);
            UserInteractionEnabled = false;

            var gridToMove = CreateNewGrid (CurrentMonthYear);
            var pointsToMove = (upwards ? 0 + _monthGridView.Lines : 0 - _monthGridView.Lines) * 44;

            if (upwards && gridToMove.weekdayOfFirst == 0)
                pointsToMove += 44;
            if (!upwards && _monthGridView.weekdayOfFirst == 0)
                pointsToMove -= 44;

            gridToMove.Frame = new RectangleF (new PointF (0, pointsToMove), gridToMove.Frame.Size);

            _scrollView.AddSubview (gridToMove);

            if (animated) {
                UIView.BeginAnimations ("changeMonth");
                UIView.SetAnimationDuration (0.4);
                UIView.SetAnimationDelay (0.1);
                UIView.SetAnimationCurve (UIViewAnimationCurve.EaseInOut);
            }

            _monthGridView.Center = new PointF (_monthGridView.Center.X, _monthGridView.Center.Y - pointsToMove);
            gridToMove.Center = new PointF (gridToMove.Center.X, gridToMove.Center.Y - pointsToMove);
            _monthGridView.Alpha = 0;
            _shadow.Frame = new RectangleF (new PointF (0, gridToMove.Lines * 44 - 88), _shadow.Frame.Size);

            var oldFrame = _scrollView.Frame;
            _scrollView.Frame = new RectangleF (_scrollView.Frame.Location, new SizeF (_scrollView.Frame.Width, (gridToMove.Lines + 1) * 44));
            _scrollView.ContentSize = _scrollView.Frame.Size;
            if (ShowToolBar) {
                var toolRect = toolbar.Frame;
                toolRect.Y = _scrollView.Frame.Y + _scrollView.Frame.Height;
                toolbar.Frame = toolRect;
            }

            SetNeedsDisplay ();

            if (animated)
                UIView.CommitAnimations ();

            _monthGridView = gridToMove;

            UserInteractionEnabled = true;
            if (oldFrame != _scrollView.Frame && SizeChanged != null)
            {
                this.Frame = new RectangleF(this.Frame.Location,Size);
                SizeChanged ();
            }
        }

Same methods

CalendarMonthView::MoveCalendarMonths ( bool upwards, bool animated ) : void

Usage Example

示例#1
0
        private bool SelectDayView(UITouch touch)
        {
            var p = touch.LocationInView(this);

            int index = ((int)p.Y / 44) * 7 + ((int)p.X / 46);

            if (index < 0 || index >= _dayTiles.Count)
            {
                return(false);
            }

            var newSelectedDayView = _dayTiles[index];

            if (newSelectedDayView == SelectedDayView)
            {
                return(false);
            }

            if (!newSelectedDayView.Active && touch.Phase != UITouchPhase.Moved)
            {
                var day = int.Parse(newSelectedDayView.Text);
                if (day > 15)
                {
                    _calendarMonthView.MoveCalendarMonths(false, true);
                }
                else
                {
                    _calendarMonthView.MoveCalendarMonths(true, true);
                }
                return(false);
            }
            else if (!newSelectedDayView.Active)
            {
                return(false);
            }

            SelectedDayView.Selected = false;
            this.BringSubviewToFront(newSelectedDayView);
            newSelectedDayView.Selected = true;

            SelectedDayView = newSelectedDayView;
            SetNeedsDisplay();
            return(true);
        }