Esempio n. 1
0
 public static void Transition(UIView fromView, UIView toView, double duration, UIViewAnimationOptions options, NSAction completion)
 {
     TransitionNotify (fromView, toView, duration, options, (x) => {
         if (completion != null)
             completion ();
     });
 }
		//Allows a UINavigationController to pop a using a custom animation 
		public static void PopControllerWithTransition(this UINavigationController 
		                                               target, UIViewAnimationOptions transition)
		{
			UIView.Transition(target.View, 0.75d, transition, delegate() {
				target.PopViewControllerAnimated(false);
			}, null);         
		}
Esempio n. 3
0
 public static void Animate(double duration, double delay, UIViewAnimationOptions options, NSAction animation, NSAction completion)
 {
     // animation null check will be done in AnimateNotify
     AnimateNotify (duration, delay, options, animation, (x) => {
         if (completion != null)
             completion ();
     });
 }
		//Allows a UINavigationController to push using a custom animation transition
		public static void PushControllerWithTransition(this UINavigationController 
		                                                target, UIViewController controllerToPush, 
		                                                UIViewAnimationOptions transition)
		{
			UIView.Transition(target.View, 0.75d, transition, delegate() {
				target.PushViewController(controllerToPush, false);
			}, null);
		}
Esempio n. 5
0
 public static void Transition(UIView withView, double duration, UIViewAnimationOptions options, NSAction animation, NSAction completion)
 {
     // animation null check will be done in AnimateNotify
     TransitionNotify(withView, duration, options, animation, (x) => {
         if (completion != null)
         {
             completion();
         }
     });
 }
Esempio n. 6
0
 public static void Animate(double duration, double delay, UIViewAnimationOptions options, NSAction animation, NSAction completion)
 {
     // animation null check will be done in AnimateNotify
     AnimateNotify(duration, delay, options, animation, (x) => {
         if (completion != null)
         {
             completion();
         }
     });
 }
Esempio n. 7
0
        void KeyboardWillShowOrHide(NSNotification notification)
        {
            UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;

            var    info        = notification.UserInfo;
            float  duration    = ((NSNumber)info.ObjectForKey(UIKeyboard.AnimationDurationUserInfoKey)).FloatValue;
            Int32  curve       = ((NSNumber)info.ObjectForKey(UIKeyboard.AnimationCurveUserInfoKey)).Int32Value;
            CGRect keyboardEnd = ((NSValue)info.ObjectForKey(UIKeyboard.FrameEndUserInfoKey)).CGRectValue;

            double sizeOfToolbar = _toolbarHolder.Frame.Height;

            if (keyboardEnd.Height != 0)
            {
                _keyboardHeight = keyboardEnd.Height;
            }

            if (orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight)
            {
                if (!UIDevice.CurrentDevice.CheckSystemVersion(8, 0) && keyboardEnd.Width != 0)
                {
                    _keyboardHeight = keyboardEnd.Width;
                }
            }

            UIViewAnimationOptions animationOptions = (UIViewAnimationOptions)(curve << 16);

            if (notification.Name == UIKeyboard.WillShowNotification)
            {
                UIView.Animate(duration, 0, animationOptions, () =>
                {
                    CGRect frame         = _toolbarHolder.Frame;
                    frame.Y              = this.View.Frame.Height - (nfloat)(_keyboardHeight + sizeOfToolbar);
                    _toolbarHolder.Frame = frame;

                    CGRect editorFrame = _webView.Frame;
                    editorFrame.Height = this.View.Frame.Height - (nfloat)(_keyboardHeight + sizeOfToolbar);
                    _webView.Frame     = editorFrame;
                }, null);
            }
            else
            {
                UIView.Animate(duration, 0, animationOptions, () =>
                {
                    CGRect frame         = _toolbarHolder.Frame;
                    frame.Y              = this.View.Frame.Height + (nfloat)_keyboardHeight;
                    _toolbarHolder.Frame = frame;

                    CGRect editorFrame = _webView.Frame;
                    editorFrame.Height = this.View.Frame.Height;
                    _webView.Frame     = editorFrame;
                }, null);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Animates a fade-out where the view starts visible and fades to hidden.
 /// </summary>
 /// <param name="views">A list of views to animate.</param>
 /// <param name="duration">The duration for the animation.</param>
 /// <param name="animationOptions">The animation options, the default is a cross dissolve transition.</param>
 public static void AnimateFadeOut(
     IEnumerable <UIView> views,
     double duration,
     UIViewAnimationOptions animationOptions = UIViewAnimationOptions.TransitionCrossDissolve)
 {
     foreach (UIView view in views)
     {
         UIView.Animate(
             duration,
             0.0,
             animationOptions,
             () => view.Alpha = 0,
             () => { });
     }
 }
Esempio n. 9
0
 private Action CreateChainedAnimationAction(Animation animation, UIViewAnimationOptions options, Action nextAction)
 {
     if (animation.IsActionOnly)
     {
         return(() =>
         {
             animation.Action();
             if (nextAction != null)
             {
                 nextAction();
             }
             else
             {
                 if (_whenCompleteAction != null)
                 {
                     _whenCompleteAction();
                 }
                 if (_repeaterAction != null)
                 {
                     _repeaterAction();
                 }
             }
         });
     }
     return(() =>
            UIView.Animate(animation.Duration, animation.Delay, options,
                           () => animation.Action(),
                           () =>
     {
         if (nextAction != null)
         {
             nextAction();
         }
         else
         {
             if (_whenCompleteAction != null)
             {
                 _whenCompleteAction();
             }
             if (_repeaterAction != null)
             {
                 _repeaterAction();
             }
         }
     }));
 }
        public async override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            UIViewController fromVC   = transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey);
            UIView           fromView = fromVC.View;
            UIViewController toVC     = transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey);
            UIView           toView   = toVC.View;

            UIView containerView = transitionContext.ContainerView;

            if (IsPresentation)
            {
                containerView.AddSubview(toView);
            }

            UIViewController animatingVC   = IsPresentation ? toVC : fromVC;
            UIView           animatingView = animatingVC.View;

            CGRect appearedFrame  = transitionContext.GetFinalFrameForViewController(animatingVC);
            CGRect dismissedFrame = appearedFrame;

            CGPoint targetLacation = dismissedFrame.Location;

            targetLacation.X       += dismissedFrame.Size.Width;
            dismissedFrame.Location = targetLacation;

            CGRect initialFrame = IsPresentation ? dismissedFrame : appearedFrame;
            CGRect finalFrame   = IsPresentation ? appearedFrame : dismissedFrame;

            animatingView.Frame = initialFrame;

            UIViewAnimationOptions opt = UIViewAnimationOptions.AllowUserInteraction
                                         | UIViewAnimationOptions.BeginFromCurrentState;
            await UIView.AnimateNotifyAsync(TransitionDuration (transitionContext), 0, 300, 5, opt, () => {
                animatingView.Frame = finalFrame;
            });

            if (!IsPresentation)
            {
                fromView.RemoveFromSuperview();
            }

            transitionContext.CompleteTransition(true);
        }
Esempio n. 11
0
        /// <summary>
        /// Animates a fade-in where the view starts hidden and fades visible.
        /// </summary>
        /// <param name="views">A list of views to animate.</param>
        /// <param name="duration">The duration for the animation.</param>
        /// <param name="delay">An optional delay before starting the animation.</param>
        /// <param name="animationOptions">The animation options, the default is a cross dissolve transition.</param>
        public static void AnimateFadeIn(
            IEnumerable <UIView> views,
            double duration,
            double delay = 0,
            UIViewAnimationOptions animationOptions = UIViewAnimationOptions.TransitionCrossDissolve)
        {
            if (delay > 0)
            {
                foreach (UIView view in views)
                {
                    view.Alpha = 0;
                }

                NSTimer.CreateScheduledTimer(delay, timer => ViewAnimation.AnimateFadeIn(views, duration, animationOptions));
            }
            else
            {
                ViewAnimation.AnimateFadeIn(views, duration, animationOptions);
            }
        }
Esempio n. 12
0
        void IFluentAnimateTail.Start()
        {
            Action nextAction = null;
            bool   stackIsEmpty;

            do
            {
                Animation animation = _actions.Pop();
                stackIsEmpty = !_actions.Any();
                UIViewAnimationOptions options = animation.AnimationOptions;
                if (_allowsUserInteraction)
                {
                    options = options | UIViewAnimationOptions.AllowUserInteraction;
                }
                if (animation.AutoReverses)
                {
                    options |= UIViewAnimationOptions.Autoreverse;
                }
                nextAction = CreateChainedAnimationAction(animation, options, nextAction);
                if (stackIsEmpty && _repeats)
                {
                    if (_repeaterDelay.HasValue)
                    {
                        animation.Delay = _repeaterDelay.Value;
                        _repeaterAction = CreateChainedAnimationAction(animation, options, nextAction);
                    }
                    else
                    {
                        _repeaterAction = nextAction;
                    }
                    _repeaterDelay = null;
                }
                _nextDelay = null;
            } while (!stackIsEmpty);
            nextAction();
        }
Esempio n. 13
0
        /**
         * Close the Menu component with animation options.
         * - Parameter duration: The time for each view's animation.
         * - Parameter delay: A delay time for each view's animation.
         * - Parameter usingSpringWithDamping: A damping ratio for the animation.
         * - Parameter initialSpringVelocity: The initial velocity for the animation.
         * - Parameter options: Options to pass to the animation.
         * - Parameter animations: An animation block to execute on each view's animation.
         * - Parameter completion: A completion block to execute on each view's animation.
         */
        public void Close(double duration = 0.15, double delay = 0, nfloat?usingSpringWithDamping = null, nfloat initialSpringVelocity = default(nfloat), UIViewAnimationOptions options = default(UIViewAnimationOptions), Action <UIView> animations = null, Action <UIView> completion = null)
        {
            usingSpringWithDamping = usingSpringWithDamping ?? 0.5f;
            if (IsEnabled)
            {
                disable();
                switch (Direction)
                {
                case MenuDirection.Up:
                {
                    closeUpAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion);
                }
                break;

                case MenuDirection.Down:
                {
                    closeDownAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion);
                }
                break;

                case MenuDirection.Left:
                {
                    closeLeftAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion);
                }
                break;

                case MenuDirection.Right:
                {
                    closeRightAnimation(duration, delay, usingSpringWithDamping.Value, initialSpringVelocity, options, animations, completion);
                }
                break;
                }
            }
        }
        public override void Transition(UIViewController fromViewController, UIViewController toViewController, double duration, UIViewAnimationOptions options, Action animations, UICompletionHandler completionHandler)
        {
            base.Transition(fromViewController, toViewController, duration, options, animations, (finished) =>
            {
                var s = this;
                if (s == null)
                {
                    return;
                }

                s.View.SendSubviewToBack(s.ContentViewController.View);
                if (completionHandler != null)
                {
                    completionHandler(finished);
                }
            });
        }
Esempio n. 15
0
        public static Task ResetAnimation(this UIView view, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            System.Diagnostics.Debug.WriteLine("Restart Started");

            var animationCompleted = new TaskCompletionSource <object> ();

            UIView.Animate(duration, 0, animationOptions,
                           () => {
                if (animationCompleted.Task.IsCanceled)
                {
                    return;
                }

                view.Transform = CGAffineTransform.MakeIdentity();
            },
                           () => animationCompleted.TrySetResult(null)
                           );

            return(animationCompleted.Task);
        }
Esempio n. 16
0
        public static Task Scale(this UIView view, float scaleAmount, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            System.Diagnostics.Debug.WriteLine("Scale Amount: {0}", scaleAmount);
            var scale = CGAffineTransform.Scale(view.Transform, scaleAmount, scaleAmount);

            var animationCompleted = new TaskCompletionSource <object> ();

            UIView.Animate(duration, 0, animationOptions,
                           () => {
                if (animationCompleted.Task.IsCanceled)
                {
                    return;
                }

                view.Transform = scale;
            },
                           () => animationCompleted.TrySetResult(null)
                           );

            return(animationCompleted.Task);
        }
Esempio n. 17
0
        private bool OpenRightViewBouncing(Action<ViewDeckController> bounced, UIViewAnimationOptions options, bool callDelegate, Action<ViewDeckController> completed)
        {
            if (this.RightController == null || FloatEqual(this.SlidingControllerView.Frame.GetMinX(), this.RightLedge)) return true;

            // check the delegate to allow opening
            if (callDelegate && this.Delegate != null && !this.Delegate.WillOpenRightView(this, true))
            {
                return false;
            }

            // also close the right view if it's open. Since the delegate can cancel the close, check the result.
            if (!this.CloseLeftView(true, options, true, completed))
            {
                return false;
            }

            // first open the view completely, run the block (to allow changes)
            UIView.Animate(OpenSlideDuration(true), 0, UIViewAnimationOptions.CurveEaseIn | UIViewAnimationOptions.LayoutSubviews, () =>
            {
                this.RightController.View.Hidden = false;
                this.SetSlidingFrameForOffset(-this.ReferenceBounds.Size.Width);
            }, () =>
            {
                // run block if it's defined
                if (bounced != null) bounced(this);
                this.CenterViewHidden();

                // now slide the view back to the ledge position
                UIView.Animate(OpenSlideDuration(true), 0, options | UIViewAnimationOptions.LayoutSubviews | UIViewAnimationOptions.BeginFromCurrentState, () =>
                {
                    this.SetSlidingFrameForOffset(this.RightLedge - this.ReferenceBounds.Size.Width);
                }, () =>
                {
                    if (completed != null)
                    {
                        completed(this);
                    }

                    if (callDelegate && this.Delegate != null)
                    {
                        this.Delegate.DidOpenRightView(this, true);
                    }

                    RefreshStatusBar();
                });
            });

            return true;
        }
Esempio n. 18
0
        private bool CloseRightView(bool animated, UIViewAnimationOptions options, bool callDelegate, Action<ViewDeckController> completed)
        {
            if (this.RightControllerIsClosed) return true;

            // check the delegate to allow closing
            if (callDelegate && this.Delegate != null && !this.Delegate.WillCloseRightView(this, true))
            {
                return false;
            }

            UIView.Animate(CloseSlideDuration(animated), 0, options | UIViewAnimationOptions.LayoutSubviews, () =>
            {
                this.SetSlidingFrameForOffset(0);
                this.CenterViewVisible();
            }, () =>
            {
                if (completed != null)
                {
                    completed(this);
                }

                this.HideAppropriateSideViews();
                if (callDelegate && this.Delegate != null)
                {
                    this.Delegate.DidCloseRightView(this, animated);
                    this.Delegate.DidShowCenterView(this, animated);
                }

                RefreshStatusBar();
            });

            return true;
        }
 public static void PushControllerWithTransition(this UINavigationController
                                                 target, UIViewController controllerToPush, UIViewAnimationOptions transition)
 {
     UIView.Transition(target.View, 0.75d, transition, delegate() {
         target.PushViewController(controllerToPush, false);
     }, null);
 }
Esempio n. 20
0
        private void ChangeContentTo(AspyViewController _newvc, AspyViewController _oldvc, UIViewAnimationOptions _animationOptions)
        {
            this._vcNew = _newvc;
            this._vcOld = _oldvc;
            //this._vcOld.View.AddSubview(this._vcNew.View);
            this._transitionComplete = new UICompletionHandler(this.TransitionComplete);
            this._animation          = new Action(delegate()
            {
                //this._vcOld.View.Alpha = 0;
                //this._vcNew.View.Alpha = 1;
            });

            // Shouldnt need to set frame sizes as these are knowns
            //_oldVC.View.Frame = _newVC.View.Frame;
            this._vcOld.WillMoveToParentViewController(null);
            this._vcNew.WillMoveToParentViewController(this);
            this.AddChildViewController(this._vcNew);

            // Let the container perform the transition
            this.Transition
            (
                _vcOld,
                _vcNew,
                this._dblAnimationDuration,
                _animationOptions,
                this._animation,
                this._transitionComplete
            );
        }
Esempio n. 21
0
        void SetupExpire()
        {
            expiryText.ShouldChangeText = (UITextView textView, NSRange NSRange, string replace) => {
                if (replace != "" && !Char.IsDigit(replace.ToCharArray() [0]))
                {
                    return(false);
                }
                CSRange range = new CSRange((int)NSRange.Location, (int)NSRange.Length);
                flashForError = false;
                updateText    = false;
                scrollForward = false;
                deleting      = false;
                ret           = false;
                deletedSpace  = false;

                if (replace.Length == 0)
                {
                    updateText = true;
                    deleting   = true;


                    if (textView.Text.Length != 0 && (range.Length != 0))       // handle case of delete when there are no characters left to delete

                    {
                        char c = textView.Text.Substring(range.Location, 1).ToCharArray() [0];
                        if (range.Location != 0 && range.Length == 1 && (c == ' ' || c == '/'))
                        {
                            range.Location--;
                            range.Length++;
                            deletedSpace = true;
                        }
                    }
                    else
                    {
                        ccText.BecomeFirstResponder();

                        if (ccText.Text.Length == (cardHelper.LengthOfFormattedStringForType(Type)))
                        {
                            ccText.Text = ccText.Text.Remove(ccText.Text.Length - 1);
                        }


                        return(EndDelegate(ccPlaceHolder, ccText, ccText.Text));
                    }
                }

                var formattedText = "";
                scrollForward = false;

                string newTextOrig = ReplaceInPlace(range.Location, range.Length, textView.Text, replace);

                int newTextLen = newTextOrig.Length;

                // Test for delete of a space or /
                if (deleting)
                {
                    formattedText = newTextOrig.Substring(0, range.Location);
                    updateText    = true;
                    return(EndDelegate(expiryPlaceHolder, expiryText, formattedText));
                }

                if (newTextLen > expiryPlaceHolder.Text.Length)
                {
                    flashForError = true;
                    return(EndDelegate(expiryPlaceHolder, expiryText, formattedText));
                }

                formattedText = newTextOrig;

                CSRange monthRange = new CSRange(expiryPlaceHolder.Text.IndexOf("MM"), 2);
                if (newTextLen > monthRange.Location)
                {
                    if (newTextOrig.Substring(monthRange.Location, 1).ToCharArray() [0] > '1')
                    {
                        // support short cut - we prepend a '0' for them


                        formattedText = ReplaceInPlace(range.Location, range.Length, textView.Text, "0" + replace);

                        newTextLen = newTextOrig.Length;
                    }
                    if (newTextLen >= (monthRange.Location + monthRange.Length))
                    {
                        cardMonth = Int32.Parse(newTextOrig.Substring(monthRange.Location, monthRange.Length));
                        if (cardMonth < 1 || cardMonth > 12)
                        {
                            flashRecheckExpiryDateMessage();
                            return(EndDelegate(expiryPlaceHolder, expiryText, formattedText));
                        }
                    }
                }

                CSRange yearRange = new CSRange(expiryPlaceHolder.Text.IndexOf("YY"), 2);
                if (newTextLen > yearRange.Location)
                {
                    int proposedDecade = (newTextOrig.Substring(yearRange.Location, 1).ToCharArray() [0] - '0') * 10;
                    int yearDecade     = currentYear - (currentYear % 10);
                    if (proposedDecade < yearDecade)
                    {
                        flashRecheckExpiryDateMessage();
                        return(EndDelegate(expiryPlaceHolder, expiryText, formattedText));
                    }
                    if (newTextLen >= (yearRange.Location + yearRange.Length))
                    {
                        year = Int32.Parse(newTextOrig.Substring(yearRange.Location, yearRange.Length));
                        int diff = year - currentYear;
                        if (diff < 0 || diff > 10)
                        {
                            flashRecheckExpiryDateMessage();
                            return(EndDelegate(expiryPlaceHolder, expiryText, formattedText));
                        }
                        if (diff == 0)
                        {
                            var todaysDate   = DateTime.Today;
                            int currentMonth = todaysDate.Month;

                            if (cardMonth < currentMonth)
                            {
                                flashRecheckExpiryDateMessage();
                                return(EndDelegate(expiryPlaceHolder, expiryText, formattedText));
                            }
                        }
                        if (creditCardImage != ccBackImage)
                        {
                            UIViewAnimationOptions transType = (Type == CardType.AMEX) ? UIViewAnimationOptions.TransitionCrossDissolve : UIViewAnimationOptions.TransitionFlipFromBottom;

                            UIImageView.Animate(
                                duration: 0.25f,
                                delay: 0,
                                options: transType,
                                animation: () => {
                                creditCardImage = ccBackImage;
                            },
                                completion: () => {
                                StatusHelpLabel.Text = "Please enter CV2";
                            });
                        }
                    }
                }
                updateText = true;
                if (formattedText.Length == 5)
                {
                    cvTwoText.BecomeFirstResponder();
                }
                return(EndDelegate(expiryPlaceHolder, expiryText, formattedText));
            };
        }
Esempio n. 22
0
        void AnimatePinStreaming(List <UILabel> images)
        {
            animationRunning = true;
            if (images.Count == 0)
            {
                animationRunning = false;

                return;
            }
            float duration = .8f;
            UIViewAnimationOptions opts = UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.Repeat;
            var image1 = images[0];
            var rand   = new Random();

            //var anim1 = new CoreAnimation.CAAnimation();

            UIView.AnimateKeyframes(duration * images.Count,
                                    delay: 0,
                                    options: UIViewKeyframeAnimationOptions.Repeat,
                                    animations: () =>
            {
                UIView.AddKeyframeWithRelativeStartTime(0, 0.15, () =>
                {
                    image1.Alpha = 1;
                });
                UIView.AddKeyframeWithRelativeStartTime(0, 0.25, () =>
                {
                    image1.Center = new CGPoint(image1.Center.X, image1.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                });

                UIView.AddKeyframeWithRelativeStartTime(0, 0.08, () =>
                {
                });


                UIView.AddKeyframeWithRelativeStartTime(0.225, 0.25, () =>
                {
                    image1.Alpha = 0;
                });



                if (images.Count > 1)
                {
                    var image2 = images[1];
                    UIView.AddKeyframeWithRelativeStartTime(0.25, 0.15, () =>
                    {
                        image2.Alpha = 1;
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.25, 0.25, () =>
                    {
                        image2.Center = new CGPoint(image2.Center.X, image2.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                    });

                    UIView.AddKeyframeWithRelativeStartTime(0.475, 0.25, () =>
                    {
                        image2.Alpha = 0;
                    });
                }

                if (images.Count > 2)
                {
                    var image3 = images[2];
                    UIView.AddKeyframeWithRelativeStartTime(0.5, 0.15, () =>
                    {
                        image3.Alpha = 1;
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.5, 0.25, () =>
                    {
                        image3.Center = new CGPoint(image3.Center.X, image3.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.725, 0.25, () =>
                    {
                        image3.Alpha = 0;
                    });
                }
                if (images.Count > 3)
                {
                    var image4 = images[3];
                    UIView.AddKeyframeWithRelativeStartTime(0.75, 0.15, () =>
                    {
                        image4.Alpha = 1;
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.75, 0.25, () =>
                    {
                        image4.Center = new CGPoint(image4.Center.X, image4.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.75, 0.25, () =>
                    {
                        image4.Alpha = 0;
                    });
                }
            }, completion: (i) =>
            {
            });

            animationRunning = false;
        }
 /**
  * A method to swap rootViewController objects.
  * - Parameter toViewController: The UIViewController to swap
  * with the active rootViewController.
  * - Parameter duration: A NSTimeInterval that sets the
  * animation duration of the transition.
  * - Parameter options: UIViewAnimationOptions thst are used
  * when animating the transition from the active rootViewController
  * to the toViewController.
  * - Parameter animations: An animation block that is executed during
  * the transition from the active rootViewController
  * to the toViewController.
  * - Parameter completion: A completion block that is execited after
  * the transition animation from the active rootViewController
  * to the toViewController has completed.
  */
 public void TransitionFromRootViewController(UIViewController toViewController, double duration = 0.5, UIViewAnimationOptions options = default(UIViewAnimationOptions), Action animations = null, Action <bool> completion = null)
 {
     RootViewController.WillMoveToParentViewController(null);
     AddChildViewController(toViewController);
     toViewController.View.Frame = RootViewController.View.Frame;
     Transition(fromViewController: RootViewController,
                toViewController: toViewController,
                duration: duration,
                options: options,
                animations: animations == null? () => { } : animations,
                completionHandler: (finished) =>
     {
         var s = this;
         toViewController.DidMoveToParentViewController(s);
         s.RootViewController.RemoveFromParentViewController();
         s.RootViewController = toViewController;
         s.RootViewController.View.ClipsToBounds      = true;
         s.RootViewController.View.AutoresizingMask   = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
         s.RootViewController.View.ContentScaleFactor = Device.Scale;
         if (completion != null)
         {
             completion(finished);
         }
     });
 }
Esempio n. 24
0
 public static void Transition(UIView withView, double duration, UIViewAnimationOptions options, NSAction animation, NSAction completion)
 {
     // animation null check will be done in AnimateNotify
     TransitionNotify (withView, duration, options, animation, (x) => {
         if (completion != null)
             completion ();
     });
 }
Esempio n. 25
0
        public static Task Rotate(this UIView view, float degrees, SpinDirection spinDirection = SpinDirection.Clockwise, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            System.Diagnostics.Debug.WriteLine("degrees: {0}", degrees);
            var rotation = CGAffineTransform.Rotate(view.Transform, (spinDirection == SpinDirection.Clockwise ? 1 : -1) * DegreesToRadians(degrees - .00001f));

            var animationCompleted = new TaskCompletionSource <object> ();

            UIView.Animate(duration, 0, animationOptions,
                           () => {
                if (animationCompleted.Task.IsCanceled)
                {
                    return;
                }

                view.Transform = rotation;
            },
                           () => animationCompleted.TrySetResult(null)
                           );

            return(animationCompleted.Task);
        }
Esempio n. 26
0
 public virtual void TransitionFromViewController(UIViewController fromViewController, UIViewController toViewController, NSTimeInterval duration, UIViewAnimationOptions options, Action animations, Action <bool> completion)
 {
 }
Esempio n. 27
0
 public static void Transition(UIView fromView, UIView toView, double duration, UIViewAnimationOptions options, Action completion)
 {
     TransitionNotify(fromView, toView, duration, options, (x) => {
         if (completion != null)
         {
             completion();
         }
     });
 }
Esempio n. 28
0
        private bool OpenRightView(bool animated, UIViewAnimationOptions options, bool callDelegate, Action<ViewDeckController> completed)
        {
            if (this.RightController == null || FloatEqual(this.SlidingControllerView.Frame.GetMaxX(), this.RightLedge)) return true;

            // check the delegate to allow opening
            if (callDelegate && this.Delegate != null && !this.Delegate.WillOpenRightView(this, animated))
            {
                return false;
            }

            // also close the left view if it's open. Since the delegate can cancel the close, check the result.
            if (!this.CloseLeftView(animated, options, callDelegate, completed))
            {
                return false;
            }

            UIView.Animate(OpenSlideDuration(animated), 0, options | UIViewAnimationOptions.LayoutSubviews, () =>
            {
                this.RightController.View.Hidden = false;
                this.SetSlidingFrameForOffset(this.RightLedge - this.ReferenceBounds.Size.Width);
                RefreshStatusBar();
                this.CenterViewHidden();
            }, () =>
            {
                if (completed != null)
                {
                    completed(this);
                }

                if (callDelegate && this.Delegate != null)
                {
                    this.Delegate.DidOpenRightView(this, animated);
                }

                RefreshStatusBar();
            });

            return true;
        }
Esempio n. 29
0
        /**
         * Close the Menu component with animation options in the Up direction.
         * - Parameter duration: The time for each view's animation.
         * - Parameter delay: A delay time for each view's animation.
         * - Parameter usingSpringWithDamping: A damping ratio for the animation.
         * - Parameter initialSpringVelocity: The initial velocity for the animation.
         * - Parameter options: Options to pass to the animation.
         * - Parameter animations: An animation block to execute on each view's animation.
         * - Parameter completion: A completion block to execute on each view's animation.
         */
        private void closeRightAnimation(double duration, double delay, nfloat usingSpringWithDamping, nfloat initialSpringVelocity, UIViewAnimationOptions options, Action <UIView> animations, Action <UIView> completion)
        {
            var v = Views;

            if (v != null)
            {
                UIView baseView = null;
                for (var i = 1; i < v.Length; i++)
                {
                    if (baseView == null)
                    {
                        baseView = v[0];
                    }
                    var view = v[i];
                    view.Hidden = false;

                    var w = BaseSize.Width;
                    UIView.AnimateNotify(duration: ((double)i) * duration,
                                         delay: delay,
                                         springWithDampingRatio: usingSpringWithDamping,
                                         initialSpringVelocity: initialSpringVelocity,
                                         options: options,
                                         animations: () =>
                    {
                        view.Alpha = 0;
                        view.SetX(baseView.X() + w);
                        if (animations != null)
                        {
                            animations(view);
                        }
                    }, completion: (bool finished) =>
                    {
                        var s       = this;
                        view.Hidden = true;
                        s.enable(view);
                        if (view == v[v.Length - 1])
                        {
                            s.IsOpened = false;
                        }
                        if (completion != null)
                        {
                            completion(view);
                        }
                    });
                }
            }
        }
Esempio n. 30
0
 protected virtual void ChangeRootViewController(UIViewController newController, UIViewAnimationOptions transition)
 {
     CoreUtility.ExecuteMethod("ChangeRootViewController", delegate()
     {
         UIViewController previousRoot = this.Window.RootViewController;
         if (this.Window.RootViewController == null)
         {
             this.Window.RootViewController = newController;
         }
         else
         {
             UIView.Transition(this.Window, 0.5, transition, delegate()
             {
                 this.Window.RootViewController = newController;
             }, null);
         }
         if (previousRoot != null)
         {
             previousRoot.Dispose();
         }
     });
 }
Esempio n. 31
0
 private void AddActionWithPreviousDuration(Action action, UIViewAnimationOptions animationOptions)
 {
     AddActionWithDuration(action, _actions.Last().Duration, animationOptions);
 }
Esempio n. 32
0
        public static Task Fade(this UIView view, FadeType fadeType = FadeType.In, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            var animationCompleted = new TaskCompletionSource <object> ();

            UIView.Animate(duration, 0, animationOptions,
                           () => {
                if (animationCompleted.Task.IsCanceled)
                {
                    return;
                }

                switch (fadeType)
                {
                case FadeType.In:
                    if (view.Alpha != 1f)
                    {
                        view.Alpha = 1f;
                    }
                    break;

                case FadeType.Out:
                    if (view.Alpha != 0f)
                    {
                        view.Alpha = 0f;
                    }
                    break;
                }
            },
                           () => animationCompleted.TrySetResult(null)
                           );

            return(animationCompleted.Task);
        }
Esempio n. 33
0
 private Action CreateChainedAnimationAction(Animation animation, UIViewAnimationOptions options, Action nextAction)
 {
     if (animation.IsActionOnly)
     {
         return () =>
         {
             animation.Action();
             if (nextAction != null) nextAction();
             else
             {
                 if (_whenCompleteAction != null) _whenCompleteAction();
                 if (_repeaterAction != null) _repeaterAction();
             }
         };
     }
     return () =>
             UIView.Animate(animation.Duration, animation.Delay, options,
                            () => animation.Action(),
                            () =>
                            {
                                if (nextAction != null) nextAction();
                                else
                                {
                                    if (_whenCompleteAction != null) _whenCompleteAction();
                                    if (_repeaterAction != null) _repeaterAction();
                                }
                            });
 }
Esempio n. 34
0
        public static Task Slide(this UIView view, SlideDirection slideDirection, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            System.Diagnostics.Debug.WriteLine("Slide Direction: {0}", slideDirection);

            CGAffineTransform startingTransform, endingTransform;

            switch (slideDirection)
            {
            case SlideDirection.FromBottom:
                startingTransform = CGAffineTransform.MakeTranslation(0f, view.Bounds.Height);
                endingTransform   = CGAffineTransform.MakeIdentity();
                break;

            case SlideDirection.FromLeft:
                startingTransform = CGAffineTransform.MakeTranslation(-view.Bounds.Width, 0f);
                endingTransform   = CGAffineTransform.MakeIdentity();
                break;

            case SlideDirection.FromRight:
                startingTransform = CGAffineTransform.MakeTranslation(view.Bounds.Width, 0f);
                endingTransform   = CGAffineTransform.MakeIdentity();
                break;

            case SlideDirection.FromTop:
                startingTransform = CGAffineTransform.MakeTranslation(0f, -view.Bounds.Height);
                endingTransform   = CGAffineTransform.MakeIdentity();
                break;

            case SlideDirection.ToBottom:
                startingTransform = CGAffineTransform.MakeIdentity();
                endingTransform   = CGAffineTransform.MakeTranslation(0f, view.Bounds.Height);
                break;

            case SlideDirection.ToLeft:
                startingTransform = CGAffineTransform.MakeIdentity();
                endingTransform   = CGAffineTransform.MakeTranslation(-view.Bounds.Width, 0f);
                break;

            case SlideDirection.ToRight:
                startingTransform = CGAffineTransform.MakeIdentity();
                endingTransform   = CGAffineTransform.MakeTranslation(view.Bounds.Width, 0f);
                break;

            case SlideDirection.ToTop:
                startingTransform = CGAffineTransform.MakeIdentity();
                endingTransform   = CGAffineTransform.MakeTranslation(0f, -view.Bounds.Height);
                break;

            default:
                startingTransform = CGAffineTransform.MakeIdentity();
                endingTransform   = CGAffineTransform.MakeIdentity();
                break;
            }

            view.Transform = startingTransform;

            var animationCompleted = new TaskCompletionSource <object> ();

            UIView.Animate(duration, 0, animationOptions,
                           () => {
                if (animationCompleted.Task.IsCanceled)
                {
                    return;
                }

                view.Transform = endingTransform;
            },
                           () => animationCompleted.TrySetResult(null)
                           );

            return(animationCompleted.Task);
        }
Esempio n. 35
0
        /**
         * Open the Menu component with animation options in the Down direction.
         * - Parameter duration: The time for each view's animation.
         * - Parameter delay: A delay time for each view's animation.
         * - Parameter usingSpringWithDamping: A damping ratio for the animation.
         * - Parameter initialSpringVelocity: The initial velocity for the animation.
         * - Parameter options: Options to pass to the animation.
         * - Parameter animations: An animation block to execute on each view's animation.
         * - Parameter completion: A completion block to execute on each view's animation.
         */
        private void openDownAnimation(double duration, double delay, nfloat usingSpringWithDamping, nfloat initialSpringVelocity, UIViewAnimationOptions options, Action <UIView> animations, Action <UIView> completion)
        {
            var v = Views;

            if (v != null)
            {
                UIView baseView = null;
                for (var i = 1; i < v.Length; i++)
                {
                    if (baseView == null)
                    {
                        baseView = v[0];
                    }
                    var view = v[i];
                    view.Hidden = false;

                    var h = BaseSize.Height;
                    UIView.AnimateNotify(duration: ((double)i) * duration,
                                         delay: delay,
                                         springWithDampingRatio: usingSpringWithDamping,
                                         initialSpringVelocity: initialSpringVelocity,
                                         options: options,
                                         animations: () =>
                    {
                        var s      = this;
                        view.Alpha = 1;
                        view.SetY(baseView.Y() + h + ((nfloat)i - 1) * s.ItemSize.Height + ((nfloat)i) * s.InterimSpace);
                        if (animations != null)
                        {
                            animations(view);
                        }
                    }, completion: (bool finished) =>
                    {
                        var s = this;
                        s.enable(view);
                        if (view == v[v.Length - 1])
                        {
                            s.IsOpened = true;
                        }
                        if (completion != null)
                        {
                            completion(view);
                        }
                    });
                }
            }
        }
Esempio n. 36
0
        public static async Task Spin(this UIView view, CancellationToken cancellationToken, int numberOfSpins = -1, SpinDirection spinDirection = SpinDirection.Clockwise, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            var splitDuration = duration / 4f;

            if (numberOfSpins > 0)
            {
                for (int i = 0; i < numberOfSpins; i++)
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        await Rotate(view, 90f, spinDirection, splitDuration, animationOptions);
                    }
                }
            }
            else
            {
                do
                {
                    await Rotate(view, 90f, spinDirection, splitDuration, animationOptions);
                } while (!cancellationToken.IsCancellationRequested);
            }

            await ResetAnimation(view, animationOptions : UIViewAnimationOptions.CurveEaseOut);
        }
Esempio n. 37
0
 public SwiperRenderer()
 {
     _animationOptions = UIViewAnimationOptions.TransitionNone;
 }
Esempio n. 38
0
        public static Task Flip(this UIView view, FlipDirection flipDirection, double duration = DefaultAnimationDuration, UIViewAnimationOptions animationOptions = UIViewAnimationOptions.CurveLinear)
        {
            var m34 = (nfloat)(-1 * 0.001);

            view.Layer.AnchorPoint = new CGPoint((nfloat)0.5, (nfloat)0.5f);

            var transform = view.Layer.Transform;

            transform.m34 = m34;

            switch (flipDirection)
            {
            case FlipDirection.TopToBottom:
                transform = transform.Rotate(DegreesToRadians(-180), 1.0f, 0.0f, 0.0f);
                break;

            case FlipDirection.BottomToTop:
                transform = transform.Rotate(DegreesToRadians(180), 1.0f, 0.0f, 0.0f);
                break;

            case FlipDirection.LeftToRight:
                transform = transform.Rotate(DegreesToRadians(180), 0.0f, -1.0f, 0.0f);
                break;

            case FlipDirection.RightToLeft:
                transform = transform.Rotate(DegreesToRadians(180), 0.0f, 1.0f, 0.0f);
                break;
            }

            var animationCompleted = new TaskCompletionSource <object> ();

            UIView.Animate(duration, 0, animationOptions,
                           () => {
                if (animationCompleted.Task.IsCanceled)
                {
                    return;
                }

                view.Layer.Transform = transform;
            },
                           () => animationCompleted.TrySetResult(null)
                           );

            return(animationCompleted.Task);
        }
Esempio n. 39
0
 private void AddActionWithPreviousDuration(Action action, UIViewAnimationOptions animationOptions)
 {
     AddActionWithDuration(action, _actions.Last().Duration, animationOptions);
 }
Esempio n. 40
0
        public override void Transition(UIViewController fromViewController, UIViewController toViewController, double duration, UIViewAnimationOptions options, Action animations, UICompletionHandler completionHandler)
        {
            TotalCalculationController totalTrans = this.Storyboard.InstantiateViewController("TotalCalculationController") as TotalCalculationController;

            if (fromViewController == totalTrans)
            {
                alertInstructions("Vault Updated!", "Your vault has been updated with your income and expenses. You can view your vault at any time and you can now start another manual entry of your financials.");
            }
        }
Esempio n. 41
0
 private void AddActionWithDuration(Action action, double duration, UIViewAnimationOptions animationOptions)
 {
     _actions.Push(new Animation
     {
         Action = action,
         AnimationOptions = animationOptions,
         Duration = duration,
         Delay = _nextDelay.HasValue ? _nextDelay.Value : 0
     });
 }