public void PresentPopover(RectangleF rect, UIView inView, UIPopoverArrowDirection arrowDirection, bool animated) { this.DismissPopover(false); if(this.ContentViewController.View != null) { //obj-C selector calls [vc getView] which calls loadView } if(this.ContentSize == SizeF.Empty) { this.ContentSize = this.ContentViewController.ContentSizeForViewInPopover; } var displayArea = CalculateDisplayArea(inView); var properties = this.Properties ?? DefaultContainerModel; var containerView = new PopoverContainerView(this.ContentSize, rect, displayArea, arrowDirection, properties); this.ArrowDirection = containerView.PopoverArrowDirection; var keyView = this.GetKeyView(); BackgroundView = new TouchableView() { Frame = keyView.Bounds }; BackgroundView.ContentMode = UIViewContentMode.ScaleToFill; BackgroundView.BackgroundColor = UIColor.Clear; BackgroundView.ViewWasTouched = this.ViewWasTouched; BackgroundView.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleBottomMargin; keyView.AddSubview(BackgroundView); containerView.Frame = inView.ConvertRectFromView(containerView.Frame, BackgroundView); BackgroundView.AddSubview(containerView); containerView.SetContentView(ContentViewController.View); containerView.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin; this.View = containerView; this.UpdateBackgroundPassthroughViews(); this.ContentViewController.ViewWillAppear(animated); this.View.BecomeFirstResponder(); if(animated) { this.View.Alpha = 0.0f; UIView.BeginAnimations("FadeIn", IntPtr.Zero); UIView.SetAnimationDuration(FadeDuration); UIView.SetAnimationDelegate(this); UIView.SetAnimationDidStopSelector(new MonoTouch.ObjCRuntime.Selector("animationDidStop:finished:context:")); this.View.Alpha = 1.0f; UIView.CommitAnimations(); } else { IsPopoverVisible = true; this.ContentViewController.ViewDidAppear(animated); } }
public void ViewWasTouched(TouchableView view) { Console.WriteLine("Touchable View was touched"); if (IsPopoverVisible && ShouldDismiss != null) { if(ShouldDismiss(this)) { Console.WriteLine("Dismissed Popover"); DismissPopover(true, true); } } }