Example #1
0
        void tap(UITapGestureRecognizer gr)
        {
            CGPoint point = gr.LocationInView(this);

            this.selectedLine = lineAtPoint(point);

            // If we just tapped, remove all lines in process
            // so that a tap does not result in a new line
            linesInProcess.Clear();

            if (selectedLine != null)
            {
                this.BecomeFirstResponder();

                // Grab the menu controller
                UIMenuController menu = UIMenuController.SharedMenuController;

                // Create a new "Delete" UIMenuItem
                UIMenuItem deleteItem = new UIMenuItem("Delete", new Selector("deleteLine:"));
                menu.MenuItems = new UIMenuItem[] { deleteItem };

                // Tell the menu item where it should come from and show it
                menu.SetTargetRect(new CGRect(point.X, point.Y, 2, 2), this);
                menu.SetMenuVisible(true, true);

                UIGestureRecognizer[] grs = this.GestureRecognizers;
                foreach (UIGestureRecognizer gestRec in grs)
                {
                    if (gestRec.GetType() != new UITapGestureRecognizer().GetType())
                    {
                        gestRec.Enabled = false;
                    }
                }
            }
            else
            {
                // Hide the menu if no line is selected
                UIMenuController menu = UIMenuController.SharedMenuController;
                menu.SetMenuVisible(false, true);

                UIGestureRecognizer[] grs = this.GestureRecognizers;
                foreach (UIGestureRecognizer gestRec in grs)
                {
                    if (gestRec.GetType() != new UITapGestureRecognizer().GetType())
                    {
                        gestRec.Enabled = true;
                    }
                }
            }
            this.SetNeedsDisplay();
        }
        partial void menuAction(NSObject sender)
        {
            this.View.BecomeFirstResponder();
            var menuController = UIMenuController.SharedMenuController;

            var red   = new UIMenuItem("Red", new Selector("redAction"));
            var blue  = new UIMenuItem("Blue", new Selector("blueAction"));
            var green = new UIMenuItem("Green", new Selector("greenAction"));

            UIMenuController menu = UIMenuController.SharedMenuController;
            var bounds            = new RectangleF(this.menuButton.Frame.X, this.menuButton.Frame.Y, 320, 110);

            menu.SetTargetRect(bounds, this.View);
            menu.MenuItems = new [] { red, blue, green };

            menu.MenuVisible = true;
        }
Example #3
0
        void swipe(UISwipeGestureRecognizer gr)
        {
            linesInProcess.Clear();
            this.BecomeFirstResponder();
            // Grab the menu controller
            UIMenuController menu = UIMenuController.SharedMenuController;

            // Create buttons
            UIMenuItem red   = new UIMenuItem("Red", new Selector("red:"));
            UIMenuItem green = new UIMenuItem("Green", new Selector("green:"));
            UIMenuItem blue  = new UIMenuItem("Blue", new Selector("blue:"));

            menu.MenuItems = new UIMenuItem[] { red, green, blue };

            // Tell the menu where it should come from and show it
            menu.SetTargetRect(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height), this);
            menu.SetMenuVisible(true, true);
        }