public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            
            var storyMenuItemImage = UIImage.FromFile("Images/AwesomeMenu/bg-menuitem.png");
            var storyMenuItemImagePressed = UIImage.FromFile("Images/AwesomeMenu/bg-menuitem-highlighted.png");
            
            var starImage = UIImage.FromFile("Images/AwesomeMenu/icon-star.png");
            
            var starMenuItem1 = new MenuItem(storyMenuItemImage, storyMenuItemImagePressed, starImage);
            var starMenuItem2 = new MenuItem(storyMenuItemImage, storyMenuItemImagePressed, starImage);
            var starMenuItem3 = new MenuItem(storyMenuItemImage, storyMenuItemImagePressed, starImage);
            
            var menu = new Menu(
                this.View.Bounds,
                UIImage.FromFile("Images/AwesomeMenu/bg-addbutton.png"),                                                               
                UIImage.FromFile("Images/AwesomeMenu/bg-addbutton-highlighted.png"),                                                               
                UIImage.FromFile("Images/AwesomeMenu/icon-plus.png"),                                                               
                UIImage.FromFile("Images/AwesomeMenu/icon-plus-highlighted.png")                                                               
                );

            menu.MenuItems.AddRange(new[] { starMenuItem1, starMenuItem2, starMenuItem3 });
            
            menu.MenuItemSelected += (sender, e) => Console.WriteLine(e.Selected);
            
            menu.BackgroundColor = UIColor.White;
            this.View.AddSubview(menu);
        }
Example #2
0
        public Menu(RectangleF frame, UIImage image, UIImage highlightImage, UIImage contentImage, UIImage highlightContentImage) : base(frame)
        {
            this.BackgroundColor = UIColor.Clear;
            this.Mode = LayoutMode.Radial;
            this.NearRadius = MenuDefaults.NearRadius;
            this.EndRadius = MenuDefaults.EndRadius;
            this.FarRadius = MenuDefaults.FarRadius;
            this.TimeOffset = MenuDefaults.TimeOffset;
            this.RotateAngle = MenuDefaults.RotateAngle;
            this.MenuWholeAngle = (float)MenuDefaults.MenuWholeAngle;
            this.StartPoint = new PointF(MenuDefaults.StartPointX, MenuDefaults.StartPointY);
            this.ExpandRotation = (float)MenuDefaults.ExpandRotation;
            this.CloseRotation = (float)MenuDefaults.CloseRotation;

            this.menuItems = new List<MenuItem>();

            this.addButton = new MenuItem(image, highlightImage, contentImage, highlightContentImage);

            this.addButton.Center = this.StartPoint;
            this.addButton.Touched += (sender, e) => this.Expanded = !this.Expanded;

            this.AddSubview(this.addButton);
        }
Example #3
0
        private void LayoutMenuItemRadial(MenuItem item, int index, int count, float step)
        {
            var endPoint = new PointF(this.StartPoint.X + (this.EndRadius - step) * (float)Math.Sin(index * this.MenuWholeAngle / count), 
                                      this.StartPoint.Y - (this.EndRadius - step) * (float)Math.Cos(index * this.MenuWholeAngle / count));

            item.EndPoint = RotateCGPointAroundCenter(endPoint, this.StartPoint, this.RotateAngle);

            var nearPoint = new PointF(this.StartPoint.X + (this.NearRadius - step) * (float)Math.Sin(index * this.MenuWholeAngle / count), 
                                       this.StartPoint.Y - (this.NearRadius - step) * (float)Math.Cos(index * this.MenuWholeAngle / count));

            item.NearPoint = RotateCGPointAroundCenter(nearPoint, this.StartPoint, this.RotateAngle);

            var farPoint = new PointF(this.StartPoint.X + (this.FarRadius - step) * (float)Math.Sin(index * this.MenuWholeAngle / count), 
                                      this.StartPoint.Y - (this.FarRadius - step) * (float)Math.Cos(index * this.MenuWholeAngle / count));

            item.FarPoint = RotateCGPointAroundCenter(farPoint, this.StartPoint, this.RotateAngle);
        }
Example #4
0
        private void LayoutMenuItemVertical(MenuItem item, int index, int count, float step)
        {
            var endPoint = new PointF(this.StartPoint.X, this.StartPoint.Y + (this.EndRadius - step));

            item.EndPoint = RotateCGPointAroundCenter(endPoint, this.StartPoint, this.RotateAngle);

            var nearPoint = new PointF(this.StartPoint.X, this.StartPoint.Y + (this.NearRadius - step));

            item.NearPoint = RotateCGPointAroundCenter(nearPoint, this.StartPoint, this.RotateAngle);

            var farPoint = new PointF(this.StartPoint.X, this.StartPoint.Y + (this.FarRadius - step));

            item.FarPoint = RotateCGPointAroundCenter(farPoint, this.StartPoint, this.RotateAngle);
        }
Example #5
0
        private void AwesomeMenuItemTouchesEnd(MenuItem item)
        {
            if (item == this.addButton) 
            {
                return;
            }

            CAAnimationGroup blowup = this.BlowupAnimationAtPoint(item.Center);

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

            for (int i = 0; i < this.MenuItems.Count; i++) 
            {
                MenuItem otherItem = this.MenuItems[i];
                CAAnimationGroup shrink = this.ShrinkAnimationAtPoint(otherItem.Center);
                if (otherItem.MenuTag == item.MenuTag) 
                {
                    continue;
                }

                otherItem.Layer.AddAnimation(shrink, "shrink");
                otherItem.Center = otherItem.StartPoint;
            }

            this.expanded = false;
            float angle = this.Expanded ? - (float)Math.PI / 4 : 0.0f;

            UIView.Animate(0.2f, () => 
            {
                this.addButton.Transform = CGAffineTransform.MakeRotation(angle);
            });

            var handler = this.MenuItemSelected;
            if (handler != null)
            {
                handler(this, new MenuItemSelectedEventArgs(item.MenuTag - 1000));
            }
        }