예제 #1
0
 public override void ViewDidAppear(bool animated)
 {
     base.ViewDidAppear(animated);
     UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseOut, () =>
     {
         this.View.BackgroundColor = OverlayColor;
         ContainerView.Transform   = CGAffineTransform.MakeIdentity();
         _actualContainerSize      = SheetSize.Fixed((float)ContainerView.Frame.Height);
     }, null);
 }
예제 #2
0
 private float HeightFor(SheetSize type)
 {
     if (type == SheetSize.HalfScreen)
     {
         return((float)(UIScreen.MainScreen.Bounds.Height / 2 + 24));
     }
     else if (type == SheetSize.FullScreen)
     {
         var insets = safeAreaInsets();
         return((float)(UIScreen.MainScreen.Bounds.Height - insets.Top - 20));
     }
     return(type.Value);
 }
예제 #3
0
 public void Resize(SheetSize toSize, bool animated = true)
 {
     if (animated)
     {
         UIView.Animate(0.2, 0, UIViewAnimationOptions.CurveEaseOut, () =>
         {
             _containerHeightConstraint.Constant = HeightFor(toSize);
             this.View.LayoutIfNeeded();
         }, null);
     }
     else
     {
         _containerHeightConstraint.Constant = HeightFor(toSize);
     }
     _containerSize       = toSize;
     _actualContainerSize = toSize;
 }
예제 #4
0
        void Panned(UIPanGestureRecognizer gesture)
        {
            var point = gesture.TranslationInView(gesture.View?.Superview);

            if (gesture.State == UIGestureRecognizerState.Began)
            {
                _firstPanPoint       = point;
                _actualContainerSize = SheetSize.Fixed((float)ContainerView.Frame.Height);
            }

            var   minHeight = Math.Min(HeightFor(_actualContainerSize), HeightFor(_orderedSheetSize.First()));
            var   maxHeight = Math.Max(HeightFor(_actualContainerSize), HeightFor(_orderedSheetSize.Last()));
            var   newHeight = Math.Max(0, HeightFor(_actualContainerSize) + _firstPanPoint.Y - point.Y);
            float offset    = 0;

            if (newHeight < minHeight)
            {
                offset    = minHeight - (float)newHeight;
                newHeight = minHeight;
            }
            if (newHeight > maxHeight)
            {
                newHeight = maxHeight;
            }

            if (gesture.State == UIGestureRecognizerState.Cancelled || gesture.State == UIGestureRecognizerState.Failed)
            {
                UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseOut, () =>
                {
                    ContainerView.Transform             = CGAffineTransform.MakeIdentity();
                    _containerHeightConstraint.Constant = HeightFor(_containerSize);
                }, null);
            }
            else if (gesture.State == UIGestureRecognizerState.Ended)
            {
                var velocity    = (0.2 * gesture.VelocityInView(this.View).Y);
                var finalHeight = newHeight - offset - velocity;
                if (velocity > 500)
                {
                    finalHeight = -1;
                }

                var animationDuration = (Math.Abs(velocity * 0.0002) + 0.2);

                if (finalHeight <= (minHeight / 2))
                {
                    UIView.Animate(animationDuration, 0, UIViewAnimationOptions.CurveEaseOut, () =>
                    {
                        this.View.BackgroundColor = UIColor.Clear;
                        ContainerView.Transform   = CGAffineTransform.MakeTranslation(0, ContainerView.Frame.Height);
                    }, () => { this.DismissViewController(false, null); });
                    return;
                }

                var newSize = _containerSize;
                if (point.Y < 0)
                {
                    newSize = _orderedSheetSize.Last() ?? _containerSize;
                    foreach (var size in _orderedSheetSize.Reverse())
                    {
                        if (finalHeight < HeightFor(size))
                        {
                            newSize = size;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    newSize = _orderedSheetSize.First() ?? _containerSize;
                    foreach (var size in _orderedSheetSize)
                    {
                        if (finalHeight > HeightFor(size))
                        {
                            newSize = size;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                _containerSize = newSize;

                UIView.Animate(animationDuration, 0, UIViewAnimationOptions.CurveEaseOut, () =>
                {
                    ContainerView.Transform             = CGAffineTransform.MakeIdentity();
                    _containerHeightConstraint.Constant = HeightFor(newSize);
                    this.View.LayoutIfNeeded();
                }, () => { _actualContainerSize = SheetSize.Fixed((float)ContainerView.Frame.Height); });
            }
            else
            {
                _containerHeightConstraint.Constant = (float)newHeight;
                if (offset > 0)
                {
                    ContainerView.Transform = CGAffineTransform.MakeTranslation(0, offset);
                }
                else
                {
                    ContainerView.Transform = CGAffineTransform.MakeIdentity();
                }
            }
        }