Exemple #1
0
 public override void TouchesEnded(NSSet touches, UIEvent evt)
 {
     if (string.IsNullOrEmpty(_disabled) && !_confirmed)
     {
         var point = (touches.AnyObject as UITouch).LocationInView(this.Superview);
         if (!Frame.Contains(point))
         {
             Lighten();
             base.TouchesCancelled(touches, evt);
         }
         else if (Selected)
         {
             Lighten();
             _confirmed = true;
             _cancelOverlay.RemoveFromSuperview();
             _cancelOverlay = null;
             base.TouchesEnded(touches, evt);
         }
         else
         {
             Lighten();
             Selected             = true;
             _cancelOverlay       = UIButton.FromType(UIButtonType.Custom);
             _cancelOverlay.Frame = new RectangleF(0, 0, 1024, 1024);
             _cancelOverlay.AddTarget(delegate { Cancel(); }, UIControlEvent.TouchDown);
             Superview.AddSubview(_cancelOverlay);
             Superview.BringSubviewToFront(this);
         }
     }
 }
        public void TrackingStarted(object sender, TrackingEventArgs e)
        {
            var button = (ButtonView)sender;

            UIGraphics.BeginImageContext(button.Bounds.Size);
            button.Layer.RenderInContext(UIGraphics.GetCurrentContext());
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            if (trackingImageView == null)
            {
                trackingImageView = new UIImageView(CGRect.Empty);
                Superview.AddSubview(trackingImageView);
                trackingImageView.Alpha = 0.5f;
            }

            trackingImageView.Image = image;
            trackingImageView.SizeToFit();
            CGRect frame    = trackingImageView.Frame;
            var    newFrame = new CGRect(Superview.ConvertPointFromView(button.Frame.Location, this), frame.Size);

            trackingImageView.Frame = newFrame;
            if (ButtonSelectedEvent != null)
            {
                ButtonSelectedEvent(button);
            }
        }
        private void initialize()
        {
            //Make new tableview and do some settings
            AutoCompleteTableView = new UITableView();
            AutoCompleteTableView.Layer.CornerRadius = 5;                                                                    //rounded corners
            AutoCompleteTableView.ContentInset       = UIEdgeInsets.Zero;
            AutoCompleteTableView.AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; //for resizing (switching from table to portait for example)
            AutoCompleteTableView.Bounces            = false;
            AutoCompleteTableView.BackgroundColor    = UIColor.Clear;
            AutoCompleteTableView.TranslatesAutoresizingMaskIntoConstraints = false;
            AutoCompleteTableView.Source          = this.AutoCompleteViewSource;
            AutoCompleteTableView.TableFooterView = new UIView();
            AutoCompleteTableView.Hidden          = true;

            //Some textfield settings
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            this.Delegate           = this;
            this.AutocorrectionType = UITextAutocorrectionType.No;
            this.ClearButtonMode    = UITextFieldViewMode.WhileEditing;

            var isTableViewController = _parentTableViewController ?? (_parentViewController as UITableViewController);

            //if parent is tableviewcontroller
            if (isTableViewController != null)
            {
                _parentIsUITableViewController = true;
                if (_parentTableViewController == null)
                {
                    _parentTableViewController = isTableViewController;
                }
                _parentTableViewBounces         = _parentTableViewController.TableView.Bounces;
                _parentTableViewAllowsSelection = _parentTableViewController.TableView.AllowsSelection;

                //Add the view to the contentview of the cell
                Superview.AddSubview(AutoCompleteTableView);

                UITableViewCell cell = Superview.Superview as UIKit.UITableViewCell;

                //Get indexpath to set the constraint to the right cell
                NSIndexPath indexPath = _parentTableViewController.TableView.IndexPathForCell(cell);

                if (indexPath == null)
                {
                    Console.WriteLine("Should be initialized in the ViewDidAppear and not in the ViewDidLoad!");
                    return;
                }
                //add constraints
                Superview.AddConstraints(
                    AutoCompleteTableView.WithSameCenterY(this).Plus((AutocompleteTableViewHeight / 2) + 10 + cell.Frame.Height * indexPath.Row),
                    AutoCompleteTableView.WithSameWidth(this),
                    AutoCompleteTableView.WithSameLeft(this),
                    AutoCompleteTableView.Height().EqualTo(AutocompleteTableViewHeight)
                    );
            }
            else
            {
                Superview.InsertSubviewBelow(AutoCompleteTableView, _parentViewController.View);

                //add constraints
                Superview.AddConstraints(
                    AutoCompleteTableView.AtTopOf(this, this.Frame.Height - 5),
                    AutoCompleteTableView.WithSameWidth(this),
                    AutoCompleteTableView.WithSameLeft(this),
                    AutoCompleteTableView.Height().EqualTo(AutocompleteTableViewHeight)
                    );
            }

            //listen to edit events
            this.EditingChanged += async(sender, eventargs) =>
            {
                if (this.Text.Length > StartAutoCompleteAfterTicks)
                {
                    showAutoCompleteView();
                    await UpdateTableViewData();
                }
            };

            this.EditingDidEnd += (sender, eventargs) =>
            {
                hideAutoCompleteView();
            };
        }