예제 #1
0
        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;
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();

     FlyingObjects = new FlyingObjectsView(View.Frame);
            View.InsertSubview(FlyingObjects, 0);

     AddChildViewController(ContainerNavigationController);
     ContainerView.AddSubview(ContainerNavigationController.View);
     ContainerView.AddConstraint(NSLayoutConstraint.Create(ContainerNavigationController.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Top, 1, 0));
     ContainerView.AddConstraint(NSLayoutConstraint.Create(ContainerNavigationController.View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Right, 1, 0));
     ContainerView.AddConstraint(NSLayoutConstraint.Create(ContainerNavigationController.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Bottom, 1, 0));
     ContainerView.AddConstraint(NSLayoutConstraint.Create(ContainerNavigationController.View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Left, 1, 0));
            ContainerNavigationController.View.TranslatesAutoresizingMaskIntoConstraints = false;

            ContainerViewTopMarginConstraint.Constant = UIApplication.SharedApplication.StatusBarFrame.Height;

           
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            AutomaticallyAdjustsScrollViewInsets = false;
            TableViewController.AutomaticallyAdjustsScrollViewInsets = false;

            TableViewController.View.TranslatesAutoresizingMaskIntoConstraints = false;
            AddChildViewController(TableViewController);
            ContainerView.AddSubview(TableViewController.View);
            ContainerView.AddConstraint(NSLayoutConstraint.Create(TableViewController.View, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Top, 1, 0));
            ContainerView.AddConstraint(NSLayoutConstraint.Create(TableViewController.View, NSLayoutAttribute.Right, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Right, 1, 0));
            ContainerView.AddConstraint(NSLayoutConstraint.Create(TableViewController.View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Bottom, 1, 0));
            ContainerView.AddConstraint(NSLayoutConstraint.Create(TableViewController.View, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ContainerView, NSLayoutAttribute.Left, 1, 0));

            RemoveBackBarButtonTitle();
        }
예제 #4
0
        public void BindDataToView(Card card, bool showNameLabel, NSIndexPath indexPath)
        {
            Reset();

            if (card == null)
            {
                return;
            }

            NameLabelHeightConstraint.Constant = (showNameLabel) ? 24 : 0;
            NameLabel.Text = card.Name;

            var cardBack = CardBack.Create();

            cardBack.BindDataToView(card, false);
            cardBack.Hidden = true;
            cardBack.Frame  = ContainerView.Bounds;
            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.BindDataToView(card, false, indexPath, true);
            cardFront.Hidden = true;
            cardFront.Frame  = ContainerView.Bounds;
            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 (card.IsFlipped)
            {
                cardBack.Hidden = false;
            }
            else
            {
                cardFront.Hidden = false;
            }
        }