private void InitializeGestures() { _cellTapGesture = new UITapGestureRecognizer(() => { if (ShowNextEntityCommand != null && ShowNextEntityCommand.CanExecute(null)) { ShowNextEntityCommand.Execute(null); } }) { NumberOfTouchesRequired = (uint)1, NumberOfTapsRequired = (uint)1 }; ContainerView.AddGestureRecognizer(_cellTapGesture); }
public override void ViewDidLoad() { base.ViewDidLoad(); IsOpen = true; var containerFrame = View.Bounds; containerFrame.X = View.Bounds.Width; ContainerView.Frame = containerFrame; ContainerView.BackgroundColor = UIColor.White; ContainerView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; View.BackgroundColor = UIColor.White; _tapGesture = new UITapGestureRecognizer(); _tapGesture.AddTarget(() => Close(true)); _tapGesture.NumberOfTapsRequired = 1; _panGesture = new UIPanGestureRecognizer { Delegate = new PanDelegate(this), MaximumNumberOfTouches = 1, MinimumNumberOfTouches = 1 }; _panGesture.AddTarget(() => Pan(ContainerView)); ContainerView.AddGestureRecognizer(_panGesture); if (_menuViewController != null) { SetMenuViewController(_menuViewController, false); } if (_mainViewController != null) { SetMainViewController(_mainViewController, false); } //Create some shadowing if (ShadowEnabled) { ContainerView.Layer.ShadowOffset = new CGSize(-5, 0); ContainerView.Layer.ShadowPath = UIBezierPath.FromRect(ContainerView.Bounds).CGPath; ContainerView.Layer.ShadowRadius = 3.0f; ContainerView.Layer.ShadowColor = UIColor.Black.CGColor; } }
private void Open(bool animated, nfloat animationTime) { if (IsOpen) { return; } if (_menuViewController != null) { _menuViewController.ViewWillAppear(animated); } Action animation = () => Animate(_menuViewController.View, ContainerView, 1); Action completion = () => { IsOpen = true; ContainerView.AddGestureRecognizer(_tapGesture); if (_menuViewController != null) { _menuViewController.ViewDidAppear(animated); } }; if (ContainerView.Subviews.Length > 0) { ContainerView.Subviews[0].UserInteractionEnabled = false; } if (animated) { UIView.Animate(animationTime, 0, AnimationOption, animation, completion); } else { animation(); completion(); } }
/// <inheritdoc /> public override void ViewWillAppear(bool animated) { SetupBackground(); PrepareCustomAnimation(); SetupLayout(); AddChildViewController(_childDialog); _childDialog.View.TranslatesAutoresizingMaskIntoConstraints = false; ContainerView.AddSubview(_childDialog.View); ContainerView.UserInteractionEnabled = true; ContainerView.AddGestureRecognizer(new UITapGestureRecognizer(() => { })); NSLayoutConstraint.ActivateConstraints(new[] { _childDialog.View.LeadingAnchor.ConstraintEqualTo(ContainerView.LeadingAnchor), _childDialog.View.TrailingAnchor.ConstraintEqualTo(ContainerView.TrailingAnchor), _childDialog.View.TopAnchor.ConstraintEqualTo(ContainerView.TopAnchor), _childDialog.View.BottomAnchor.ConstraintEqualTo(ContainerView.BottomAnchor), }); _childDialog.DidMoveToParentViewController(this); RootView.AddGestureRecognizer(GetTappedOutsideGestureRecognizer()); }
public override void ViewDidLoad() { base.ViewDidLoad(); NameTextField.Enabled = Editable; NameTextField.AttributedPlaceholder = new NSAttributedString(Strings.Basic.new_card, new UIStringAttributes { ForegroundColor = UIColor.Gray }); NameTextField.EditingChanged += (sender, e) => { SelectedCard.UpdateStringProperty(() => SelectedCard.Name, NameTextField.Text.Trim()); }; NameTextField.Hidden = HideTitle; var cardBack = CardBack.Create(); cardBack.Hidden = true; cardBack.Frame = ContainerView.Bounds; cardBack.LogoImageButtonAction += () => { var isTablet = CrossDeviceInfo.Current.Idiom == Idiom.Tablet; var alertStyle = isTablet ? UIAlertControllerStyle.Alert : UIAlertControllerStyle.ActionSheet; UIAlertController AlertController = UIAlertController.Create(Strings.Alerts.select_image_source, null, alertStyle); AlertController.AddAction(UIAlertAction.Create(Strings.Alerts.user_facebook_image, UIAlertActionStyle.Default, (obj) => { DownloadFacebookImage(cardBack, SelectedCard.LocalLogoURL, SelectedCard.RemoteLogoURL, "Logo.png", SelectedCard.RemoteLogoURL); })); AlertController.AddAction(UIAlertAction.Create(Strings.Alerts.select_from_gallery, UIAlertActionStyle.Default, (obj) => { SelectImageFromGallery(cardBack, SelectedCard.LocalLogoURL, SelectedCard.RemoteLogoURL, "Logo.png",SelectedCard.RemoteLogoURL); })); AlertController.AddAction(UIAlertAction.Create(Strings.Basic.cancel, UIAlertActionStyle.Cancel, null)); PresentViewController(AlertController, true, null); }; ContainerView.AddSubview(cardBack); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardBack, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Top, 1, 0)); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardBack, NSLayoutAttribute.Right, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Right, 1, 0)); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardBack, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Bottom, 1, 0)); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardBack, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Left, 1, 0)); var cardFront = CardFront.Create(); cardFront.Hidden = true; cardFront.Frame = ContainerView.Bounds; cardFront.HeaderImageButtonAction += () => { var isTablet = CrossDeviceInfo.Current.Idiom == Idiom.Tablet; var alertStyle = isTablet ? UIAlertControllerStyle.Alert : UIAlertControllerStyle.ActionSheet; UIAlertController AlertController = UIAlertController.Create(Strings.Alerts.select_image_source, null, alertStyle); AlertController.AddAction(UIAlertAction.Create(Strings.Alerts.user_facebook_image, UIAlertActionStyle.Default, (obj) => { DownloadFacebookImage(cardFront, SelectedCard.LocalHeaderURL, SelectedCard.RemoteHeaderURL, "Header.png", SelectedCard.RemoteHeaderURL); })); AlertController.AddAction(UIAlertAction.Create(Strings.Alerts.select_from_gallery, UIAlertActionStyle.Default, (obj) => { SelectImageFromGallery(cardFront, SelectedCard.LocalHeaderURL, SelectedCard.RemoteHeaderURL, "Header.png", SelectedCard.RemoteHeaderURL); })); AlertController.AddAction(UIAlertAction.Create(Strings.Basic.cancel, UIAlertActionStyle.Cancel, null)); PresentViewController(AlertController, true, null); }; ContainerView.AddSubview(cardFront); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardFront, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Top, 1, 0)); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardFront, NSLayoutAttribute.Right, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Right, 1, 0)); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardFront, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Bottom, 1, 0)); ContainerView.AddConstraint(NSLayoutConstraint.Create(cardFront, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Left, 1, 0)); if (SelectedCard.IsFlipped) { cardBack.Hidden = false; } else { cardFront.Hidden = false; } var SwipeGestureRecognizer = new UISwipeGestureRecognizer((UISwipeGestureRecognizer obj) => { Flip(); }); SwipeGestureRecognizer.Direction = UISwipeGestureRecognizerDirection.Left | UISwipeGestureRecognizerDirection.Right; ContainerView.AddGestureRecognizer(SwipeGestureRecognizer); } public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); Update(true); CABasicAnimation grow = CABasicAnimation.FromKeyPath("transform.scale"); grow.From = NSObject.FromObject(0); grow.Duration = .5; grow.RemovedOnCompletion = true; ContainerView.Layer.AddAnimation(grow, "grow"); } public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); TableViewRowEditingChangedNotification = NSNotificationCenter.DefaultCenter.AddObserver(new NSString(Strings.InternalNotifications.notification_table_row_editing_changed), (obj) => { InvokeOnMainThread(() => { Update(false); }); }); } public override void ViewDidDisappear(bool animated) { base.ViewDidDisappear(animated); TableViewRowEditingChangedNotification?.Dispose(); TableViewRowEditingChangedNotification = null; } public override void ViewWillLayoutSubviews() { base.ViewWillLayoutSubviews(); if (ContainerView != null) { ContainerView.Frame = new CGRect(8, 8, View.Bounds.Width - 16, GetCalculatedHeight() + 33); //40 is the total insets that appear in a tableviewcell var cardFront = ContainerView.Subviews.Where(c => c.GetType() == typeof(CardFront)).FirstOrDefault() as CardFront; if (cardFront != null) cardFront.Frame = ContainerView.Bounds; var cardBack = ContainerView.Subviews.Where(c => c.GetType() == typeof(CardBack)).FirstOrDefault() as CardBack; if (cardBack != null) cardBack.Frame = ContainerView.Bounds; } } protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { ContainerView.Subviews.ToList().ForEach(v => v.RemoveFromSuperview()); ContainerView?.RemoveFromSuperview(); ContainerView?.Dispose(); ContainerView = null; TableViewRowEditingChangedNotification?.Dispose(); TableViewRowEditingChangedNotification = null; } } public void FocusOnName() { NameTextField.BecomeFirstResponder(); } public void Update(bool reloadImages) { if (SelectedCard == null) return; NameTextField.Text = (SelectedCard.Name.Equals(Strings.Basic.new_card, StringComparison.InvariantCultureIgnoreCase) && Editable) ? null : SelectedCard.Name; var cardFront = ContainerView.Subviews.Where(c => c.GetType() == typeof(CardFront)).FirstOrDefault() as CardFront;