public void Show()
 {
     Animate(0.4, () => {
         heightConstraint.Constant = Superview.Frame.Size.Height;
         label.Hidden  = false;
         button.Hidden = false;
         Superview.LayoutIfNeeded();
     });
 }
Example #2
0
        private void Show()
        {
            Superview?.LayoutIfNeeded();
            verticalConstraint.Constant = 0;

            UIView.Animate(0.4, 0.2, UIViewAnimationOptions.TransitionNone, () => { textLabel.Alpha = 1.0f; }, (() =>
            {
            }));

            UIView.Animate(0.4, 0, UIViewAnimationOptions.CurveEaseOut, () => Superview?.LayoutIfNeeded(), Hide);
        }
Example #3
0
        private void AnimateMenu(int newHeight, UICompletionHandler completionBlock)
        {
            if (completionBlock == null)
            {
                completionBlock = (finished) => { };
            }

            var constraint = GetChangedConstraint();

            constraint.Constant = newHeight;

            // if using spring animation extend duration because spring animation is included
            //    in duration
            AnimateNotify(
                duration: AnimationDuration,
                delay: 0,
                springWithDampingRatio: UseSpringAnimation ? SpringWithDampingRatio : 1,               //0.5
                initialSpringVelocity: UseSpringAnimation ? InitialSpringVelocity : 1,                 //0.8
                options: UIViewAnimationOptions.CurveEaseInOut,
                animations: () => {
                // must call LayoutIfNeeded on Superview or change will not animate
                if (Superview != null)
                {
                    Superview.LayoutIfNeeded();
                }
            },
                completion: completionBlock);

            ViewExpanded = newHeight == ExpandedSize;

            if (ViewExpanded && MenuOpenHandler != null)
            {
                MenuOpenHandler();
            }
            else if (ViewExpanded == false && MenuClosedHandler != null)
            {
                MenuClosedHandler();
            }
        }
Example #4
0
 private void Hide()
 {
     verticalConstraint.Constant = currentHeight;
     UIView.Animate(0.4, _durations[lunchDuration], UIViewAnimationOptions.TransitionNone, () => Superview?.LayoutIfNeeded(), RemoveFromSuperview);
 }
        private void EstablishNotificationHandlers()
        {
            NSNotificationCenter.DefaultCenter.AddObserver(
                UIKeyboard.WillShowNotification,
                notification => {
                if (this.Superview == null)
                {
                    return;
                }

                var userInfo = notification.UserInfo;


                float duration = default(float);

                if (!float.TryParse(userInfo[UIKeyboard.AnimationDurationUserInfoKey].ToString(), out duration))
                {
                    return;
                }

                if (Window == null)
                {
                    return;
                }

                RectangleF keyboardFrameEnd = this.Superview.ConvertRectFromView(
                    ((NSValue)userInfo[UIKeyboard.FrameEndUserInfoKey]).RectangleFValue, this.Window);


                var windowFrame = this.Superview.ConvertRectFromView(Window.Frame, Window);

                var heightOffset = (windowFrame.Size.Height - keyboardFrameEnd.Y) - this.Superview.Frame.Y;

                heightConstraint.Constant = heightOffset;

                UIView.Animate(duration, () => {
                    this.Superview.LayoutIfNeeded();
                });

                if (this.Superview is UIScrollView)
                {
                    var keyboardFrameBegin = this.Superview.ConvertRectFromView(
                        ((NSValue)userInfo[UIKeyboard.FrameBeginUserInfoKey]).RectangleFValue, this.Window);

                    keyboardFrameBegin = this.Superview.ConvertRectFromView(keyboardFrameBegin, null);

                    var contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardFrameBegin.Size.Height, 0.0f);

                    var scrollViewParent = this.Superview as UIScrollView;

                    scrollViewParent.ScrollIndicatorInsets =
                        scrollViewParent.ContentInset      =
                            contentInsets;

                    var aRect = new RectangleF(scrollViewParent.Frame.Location, new SizeF(scrollViewParent.Frame.Width, scrollViewParent.Frame.Height - keyboardFrameBegin.Size.Height));

                    UIView activeView = null;

                    foreach (var subView in scrollViewParent.Subviews)
                    {
                        if (subView.IsFirstResponder)
                        {
                            activeView = subView;
                            break;
                        }
                    }

                    if (activeView != null && !aRect.Contains(activeView.Frame.Location))
                    {
                        scrollViewParent.SetContentOffset(
                            new PointF(scrollViewParent.ContentOffset.X, activeView.Frame.Location.Y), true);
                    }
                }
            });


            NSNotificationCenter.DefaultCenter.AddObserver(
                UIKeyboard.WillHideNotification,
                notification => {
                if (this.Superview == null)
                {
                    return;
                }

                var userInfo = notification.UserInfo;

                float duration = default(float);

                if (!float.TryParse(userInfo[UIKeyboard.AnimationDurationUserInfoKey].ToString(), out duration))
                {
                    return;
                }

                heightConstraint.Constant = 0.0f;

                UIView.Animate(duration, () => {
                    Superview.LayoutIfNeeded();
                });
            });
        }