Exemple #1
0
        private void SetMenu()
        {
            int count = MenusArray.Count;

            for (int i = 0; i < count; i++)
            {
                ApexMenuItem item = MenusArray[i];
                item.Tag        = 1000 + i;
                item.StartPoint = StartPoint;

                // avoid overlap
                if (MenuWholeAngle >= Math.PI * 2)
                {
                    MenuWholeAngle = MenuWholeAngle - MenuWholeAngle / count;
                }
                PointF endPoint = new PointF(StartPoint.X + EndRadius * (float)Math.Sin(i * MenuWholeAngle / (count - 1)), StartPoint.Y - EndRadius * (float)Math.Cos(i * MenuWholeAngle / (count - 1)));
                item.EndPoint = RotateCGPointAroundCenter(endPoint, StartPoint, RotateAngle);
                PointF nearPoint = new PointF(StartPoint.X + NearRadius * (float)Math.Sin(i * MenuWholeAngle / (count - 1)), StartPoint.Y - NearRadius * (float)Math.Cos(i * MenuWholeAngle / (count - 1)));
                item.NearPoint = RotateCGPointAroundCenter(nearPoint, StartPoint, RotateAngle);
                PointF farPoint = new PointF(StartPoint.X + FarRadius * (float)Math.Sin(i * MenuWholeAngle / (count - 1)), StartPoint.Y - FarRadius * (float)Math.Cos(i * MenuWholeAngle / (count - 1)));
                item.FarPoint = RotateCGPointAroundCenter(farPoint, StartPoint, RotateAngle);
                item.Center   = item.StartPoint;
                //item.delegate = this;
                this.InsertSubviewBelow(item, StartButton);
            }
        }
Exemple #2
0
        //AwesomeMenuItem delegates

        public void ApexMenuItemTouchesBegan(ApexMenuItem item)
        {
            if (item == StartButton)
            {
                this.Expanding = !this.Expanding;
            }
        }
Exemple #3
0
        //Private methods
        private void Expand()
        {
            if (Flag == MenusArray.Count)
            {
                IsAnimating = flase;
                Timer.Invalidate();
                Timer = null;
                return;
            }

            var          Tag             = 1000 + Flag;
            ApexMenuItem item            = this.ViewWithTag(Tag);
            var          rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");

            rotateAnimation.Values   = new NSNumber[] { this.ExpandRotation, 0.0f };
            rotateAnimation.Duration = AnimationDuration;
            rotateAnimation.KeyTimes = new NSNumber[] { 0.3f, 0.4f };

            var positionAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");

            positionAnimation.Duration = AnimationDuration;

            var path = new CGPath();

            path.MoveToPoint(item.StartPoint.X, item.StartPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.NearPoint.X, item.NearPoint.Y);
            path.AddLineToPoint(item.EndPoint.X, item.EndPoint.Y);
            positionAnimation.Path = path;

            var animationGroup = new CAAnimationGroup();

            animationGroup.Animations     = new CAAnimation[] { positionAnimation, rotateAnimation };
            animationGroup.Duration       = AnimationDuration;
            animationGroup.FillMode       = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            //animationgroup.delegate = self;

            if (Flag == MenusArray.Count - 1)
            {
                animationGroup.SetValueForKey("firstAnimation", "id");
            }
            item.Layer.AddAnimation(animationGroup, "Expand");
            item.Center = item.EndPoint;
            Flag++;
        }
Exemple #4
0
        public void ApexMenuItemTouchesEnd(ApexMenuItem item)
        {
            // exclude the "add" button
            if (item == StartButton)
            {
                return;
            }
            // blowup the selected menu button
            CAAnimationGroup blowup = this.BlowupAnimationAtPoint(item.Center);

            item.Layer.AddAnimation(blowup, "blowup");
            item.Center = item.StartPoint;

            // shrink other menu buttons
            for (int i = 0; i < MenusArray.Count; i++)
            {
                ApexMenuItem     otherItem = MenusArray[i];
                CAAnimationGroup shrink    = this.ShrinkAnimationAtPoint(otherItem.center);
                if (otherItem.Tag == item.Tag)
                {
                    continue;
                }
                otherItem.Layer.AddAnimation(shrink, "shrink");

                otherItem.Center = otherItem.StartPoint;
            }
            Expanding = false;

            // rotate start button
            float angle = this.Expanding ? Math.PI / 4.0f : 0.0f;

            Animate(AnimationDuration, () => {
                StartButton.Transform = CGAffineTransform.MakeRotation(angle);
            });

            //if ([_delegate respondsToSelector:@selector(awesomeMenu:didSelectIndex:)])
            //{
            //	[_delegate awesomeMenu:self didSelectIndex:item.tag - 1000];
            //}
        }
Exemple #5
0
        public ApexMenu(RectangleF frame, ApexMenuItem startItem, List <ApexMenuItem> aMenusArray) : base(frame)
        {
            this.BackgroundColor = UIColor.Clear;

            this.NearRadius        = kApexMenuDefaultNearRadius;
            this.EndRadius         = kApexMenuDefaultEndRadius;
            this.FarRadius         = kApexMenuDefaultFarRadius;
            this.TimeOffset        = kApexMenuDefaultTimeOffset;
            this.RotateAngle       = kApexMenuDefaultRotateAngle;
            this.MenuWholeAngle    = kApexMenuDefaultMenuWholeAngle;
            this.StartPoint        = new PointF(kApexMenuDefaultStartPointX, kApexMenuDefaultStartPointY);
            this.ExpandRotation    = kApexMenuDefaultExpandRotation;
            this.CloseRotation     = kApexMenuDefaultCloseRotation;
            this.AnimationDuration = kApexMenuDefaultAnimationDuration;

            this.MenusArray = aMenusArray;

            // assign startItem to "Add" Button.
            this.StartButton = startItem;
            //_startButton.delegate = self;
            StartButton.Center = this.StartPoint;
            this.AddSubview(StartButton);
        }