Ejemplo n.º 1
0
        public static UIImage CreateBlurImageFromView(UIView view)
        {
            var blurRadius = 2f;

            var _size = view.Bounds.Size;

            UIGraphics.BeginImageContext(_size);
            view.DrawViewHierarchy(view.Bounds, false);
            var viewImage = UIGraphics.GetImageFromCurrentImageContext();

            // Blur Image
            var gaussianBlurFilter = new CIGaussianBlur();

            gaussianBlurFilter.Image  = CIImage.FromCGImage(viewImage.CGImage);
            gaussianBlurFilter.Radius = blurRadius;
            var resultImage = gaussianBlurFilter.OutputImage;

            var croppedImage    = resultImage.ImageByCroppingToRect(new CGRect(blurRadius, blurRadius, _size.Width - 2 * blurRadius, _size.Height - 2 * blurRadius));
            var transformFilter = new CIAffineTransform();
            var affineTransform = CGAffineTransform.MakeTranslation(-blurRadius, blurRadius);

            transformFilter.Transform = affineTransform;
            transformFilter.Image     = croppedImage;
            var transformedImage = transformFilter.OutputImage;

            return(new UIImage(transformedImage));
        }
        public override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            base.AnimateTransition(transitionContext);

            Action animation = null;

            if (IsPresenting)
            {
                toView.Frame     = transitionContext.ContainerView.Bounds;
                toView.Transform = CGAffineTransform.MakeTranslation(0, toView.Frame.Size.Height);
                transitionContext.ContainerView.AddSubview(toView);
                animation = () => toView.Transform = CGAffineTransform.MakeIdentity();
            }
            else
            {
                toView.Frame = transitionContext.ContainerView.Bounds;
                transitionContext.ContainerView.InsertSubviewBelow(toView, fromView);
                animation = () => fromView.Transform = CGAffineTransform.MakeTranslation(0, toView.Frame.Size.Height);
            }

            animator = CreateDefaultAnimator();
            animator.AddCompletion(position => transitionContext.CompleteTransition(true));
            animator.AddAnimations(animation);
            animator.StartAnimation();
        }
Ejemplo n.º 3
0
        private CGAffineTransform?GetMaskTransform(VisualElement visualElement)
        {
            if (!(visualElement is Layout layout))
            {
                return(null);
            }

            var minChildrenStartX = layout.Padding.Left;
            var minChildrenStartY = layout.Padding.Top;

            /*
             * To find the clipping mask for the subview we must
             * calculate the minimum start x and y for the child views.
             *
             * To find the minimum start in one axis, we must add the padding
             * of the layout and the margin of the child view.
             */
            var visualElementChildren = layout.Children?.Where(element => element is VisualElement).ToList();

            if (visualElementChildren != null && visualElementChildren.Any())
            {
                minChildrenStartX += visualElementChildren.Min(element => ((VisualElement)element).X);
                minChildrenStartY += visualElementChildren.Max(element => ((VisualElement)element).Y);
            }

            return(CGAffineTransform.MakeTranslation(-(float)minChildrenStartX, -(float)minChildrenStartY));
        }
Ejemplo n.º 4
0
    /// <summary>
    ///     Slides a view vertically out of focus.
    /// </summary>
    /// <param name="direction">The direction to slide the view in via. Top (positive) or bottom (negative).</param>
    /// <param name="animDuration">The duration of the animation.</param>
    /// <param name="delay">The delay before the animation starts.</param>
    /// <param name="finishedAction">The action invoked upon animation completion.</param>
    public static void SlideOutVertically(this UIView view, int direction, float animDuration, float delay = 0, Action finishedAction = null)
    {
        view.Transform = CGAffineTransform.MakeIdentity();

        UIView.AnimateNotify(animDuration, delay, UIViewAnimationOptions.CurveEaseInOut, () =>
        {
            nfloat ty;

            if (direction > 0)
            {
                ty = 0 - view.Frame.Height;
            }

            else
            {
                ty = MessagingServiceCore.Window.Bounds.Height - view.Frame.Y;
            }

            view.Transform = CGAffineTransform.MakeTranslation(0, ty);
        }, (hasFinished) =>
        {
            if (hasFinished)
            {
                finishedAction?.Invoke();
            }
        });
    }
Ejemplo n.º 5
0
        protected virtual void DrawHeart(CGContext context, float x, float y, float width, float height, float cornerRadius, bool fill, bool stroke)
        {
            var length = Math.Min(height, width);

            var startPoint = new CGPoint(x, y + 2f * length / 3f);
            var p1         = new CGPoint(x, y + length);
            var p2         = new CGPoint(x + 2f * length / 3f, y + length);
            var c1         = new CGPoint(x + 2f * length / 3f, y + 2f * length / 3f);
            var c2         = new CGPoint(x + length / 3f, y + length / 3f);
            var radius     = length / 3f;

            var path = new CGPath();

            path.MoveToPoint(startPoint.X, startPoint.Y);

            path.AddArcToPoint(p1.X, p1.Y, p2.X, p2.Y, cornerRadius);
            path.AddLineToPoint(p2.X, p2.Y);
            path.AddArc(c1.X, c1.Y, radius, (float)-Math.PI / 2f, (float)Math.PI / 2f, false);
            path.AddArc(c2.X, c2.Y, radius, 0f, (float)Math.PI, true);
            path.CloseSubpath();

            var transform = CGAffineTransform.MakeTranslation(-length / 3f, -length * 2f / 3f);

            transform.Rotate((float)-Math.PI / 4f);
            transform.Scale(0.85f, 0.85f);
            transform.Translate(width / 2f, 1.1f * height / 2f);
            path = path.CopyByTransformingPath(transform);
            context.AddPath(path);

            this.DrawPath(context, fill, stroke);
        }
Ejemplo n.º 6
0
 void SlideView(UIView b, bool up)
 {
     UIView.Animate(.1f, 0f,
                    0,
                    () => { b.Layer.AffineTransform = CGAffineTransform.MakeTranslation(0, up?-10:10); },
                    () => { b.Layer.AffineTransform = CGAffineTransform.MakeTranslation(0, 0); });
 }
Ejemplo n.º 7
0
        void ApplyAnimation(UIView view, CAMediaTimingFunction timingFunction, Action <bool> completion)
        {
            var animationWidth = View.Frame.Width - view.Frame.Width - (offset * 2);

            if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                animationWidth -= View.SafeAreaInsets.Left + View.SafeAreaInsets.Right;
            }

            var transform = CGAffineTransform.MakeTranslation(animationWidth, 0);

            UIViewMDCTimingFunction.Animate(timingFunction,
                                            animationTimeInterval,
                                            animationTimeDelay,
                                            0,
                                            () => view.Transform = transform,
                                            HandleAction);

            void HandleAction(bool obj)
            {
                UIViewMDCTimingFunction.Animate(timingFunction,
                                                animationTimeInterval,
                                                animationTimeDelay,
                                                0,
                                                () => view.Transform = CGAffineTransform.MakeIdentity(),
                                                completion);
            }
        }
Ejemplo n.º 8
0
        CAShapeLayer CreateShapeLayerWithBezierPath(UIBezierPath bezierPath)
        {
            /* Expand the shape bounds, so when it scales down a bit in the beginning, we have some padding */
            var shapeBounds = Bounds.Inset(-Bounds.Width, -Bounds.Height);

            using (var mutablePath = new CGPath()) {
                mutablePath.AddRect(shapeBounds);

                /* Move the icon to the middle */
                var iconOffset = new CGPoint((Bounds.Width - bezierPath.Bounds.Width) / 2,
                                             (Bounds.Height - bezierPath.Bounds.Height) / 2);

                var iconTransform = CGAffineTransform.MakeTranslation(iconOffset.X, iconOffset.Y);

                mutablePath.AddPath(iconTransform, bezierPath.CGPath);

                var shapeLayer = (CAShapeLayer)CAShapeLayer.Create();
                shapeLayer.Bounds      = shapeBounds;
                shapeLayer.Position    = new CGPoint(Bounds.Width / 2, Bounds.Height / 2);
                shapeLayer.Path        = mutablePath;
                shapeLayer.AnchorPoint = new CGPoint(0.5, 0.5);
                shapeLayer.FillColor   = BackgroundViewColor.CGColor;

                return(shapeLayer);
            }
        }
Ejemplo n.º 9
0
        protected virtual void DrawPoints(CGContext context, List <CGPoint> points, float cornerRadius, bool fill, bool stroke, float x = 0f, float y = 0f)
        {
            if (points == null || points.Count == 0)
            {
                return;
            }

            var midPoint = new CGPoint(0.5 * (points[0].X + points[1].X), 0.5 * (points[0].Y + points[1].Y));
            var path     = new CGPath();

            path.MoveToPoint(midPoint);

            for (var i = 0; i < points.Count; ++i)
            {
                path.AddArcToPoint(points[(i + 1) % points.Count].X, points[(i + 1) % points.Count].Y, points[(i + 2) % points.Count].X, points[(i + 2) % points.Count].Y, cornerRadius);
            }

            path.CloseSubpath();

            var transform = CGAffineTransform.MakeTranslation(x, y);

            //path = path.CopyByTransformingPath(transform);

            context.AddPath(path);

            this.DrawPath(context, fill, stroke);
        }
Ejemplo n.º 10
0
        void setOrientation()
        {
            var toInterfaceOrientation = InterfaceOrientation;

            switch (toInterfaceOrientation)
            {
            case UIInterfaceOrientation.LandscapeLeft:
                View.Transform = CGAffineTransform.MakeRotation(0);
                View.Frame     = new CGRect(0, 0, 1024, 768);
                break;

            case UIInterfaceOrientation.LandscapeRight:
                View.Transform = CGAffineTransform.MakeRotation(0);
                View.Frame     = new CGRect(0, 0, 1024, 768);
                break;

            case UIInterfaceOrientation.Portrait:

                View.Transform = CGAffineTransform.MakeTranslation(128, 0);
                View.Transform = CGAffineTransform.MakeRotation((nfloat)Math.PI / 2);
                View.Frame     = new CGRect(0, 0, 768, 1024);
                break;

            case UIInterfaceOrientation.PortraitUpsideDown:
                View.Transform = CGAffineTransform.MakeTranslation(128, 0);
                View.Transform = CGAffineTransform.MakeRotation((nfloat)Math.PI / 2);
                View.Frame     = new CGRect(0, 0, 768, 1024);
                break;
            }
        }
Ejemplo n.º 11
0
            /// <summary>
            /// Shows the picker
            /// </summary>
            public void Show()
            {
                var window = UIApplication.SharedApplication.KeyWindow;

                if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
                {
                    this.popover.PresentFromRect(this.targetView.Superview.ConvertRectToView(this.targetView.Frame, window), window, UIPopoverArrowDirection.Any, true);
                }
                else
                {
                    var vc = window.RootViewController;

                    this.fadeView.Frame = vc.View.Frame;
                    if (this.fadeView.Superview != vc.View)
                    {
                        this.fadeView.RemoveFromSuperview();
                        vc.View.AddSubview(this.fadeView);
                    }
                    this.fadeView.Alpha = 0;
                    var f = this.navigation.View.Frame;
                    f.Y    = this.fadeView.Frame.Height - this.navigationSize.Height;
                    f.Size = this.navigationSize;
                    this.navigation.View.Frame     = f;
                    this.navigation.View.Transform = CGAffineTransform.MakeTranslation(0, f.Height);
                    UIView.Animate(0.3, () =>
                    {
                        this.fadeView.Alpha            = 1;
                        this.navigation.View.Transform = CGAffineTransform.MakeIdentity();
                    });
                }
            }
Ejemplo n.º 12
0
        public void RenderExplodedMine()
        {
            RemoveAllChildren();
            var s    = new SKShapeNode();
            var path = new CGPath();

            path.MoveToPoint(0, 0);
            path.AddLineToPoint(size, 0);
            path.AddLineToPoint(size, size);
            path.AddLineToPoint(0, size);
            path.AddLineToPoint(0, 0);
            s.Path        = path.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s.StrokeColor = NSColor.FromCalibratedRgb(0.502f, 0.502f, 0.502f);
            s.FillColor   = NSColor.FromCalibratedRgb(0.8f, 0.8f, 0.8f);
            AddChild(s);

            var s1 = new SKShapeNode();
            var p1 = new CGPath();

            p1.AddArc(x * size + size / 2, y * size + size / 2, size / 4, 0, 2 * (float)Math.PI, true);
            s1.Path        = p1;
            s1.StrokeColor = NSColor.FromCalibratedRgb(0.2f, 0.2f, 0.2f);
            s1.FillColor   = NSColor.FromCalibratedRgb(0.8f, 0.0f, 0.0f);
            AddChild(s1);
        }
Ejemplo n.º 13
0
        private void UpdateElementsOnScreen(float roll, float pitch, float yaw)
        {
            //var roll = reading.RollDegrees * Math.PI / 180.0;
            //var pitch = reading.PitchDegrees * Math.PI / 180.0;
            //var yaw = reading.YawDegrees * Math.PI / 180.0;

            foreach (var evt in events)
            {
                var fe = evt.Key as UITextView;
                if (fe == null || fe.Bounds.Height == 0 || fe.Bounds.Width == 0)
                {
                    continue;
                }
                //var element = fe.DataContext as IWorldElement<Event>;
                //if (element == null) continue;
                var element = events[fe];
                if (element == null)
                {
                    continue;
                }

                var offset = ViewModel.CalculateScreenOffset(element, fe.Bounds.Width, fe.Bounds.Height, roll, pitch, yaw);
                var tf     =
                    CGAffineTransform.MakeTranslation((float)offset.TranslateX, (float)offset.TranslateY);
                tf.Scale((float)offset.Scale, (float)offset.Scale);
                fe.Transform = tf;
            }
        }
Ejemplo n.º 14
0
        private void DrawFlag()
        {
            var s1 = new SKShapeNode();
            var p1 = new CGPath();

            p1.MoveToPoint(size / 3.0f, size / 2.0f);
            p1.AddLineToPoint(size / 3.0f * 2, size / 3.0f);
            p1.AddLineToPoint(size / 3.0f * 2, size / 3.0f * 2);
            s1.Path        = p1.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s1.StrokeColor = NSColor.Red;
            s1.FillColor   = NSColor.Red;
            AddChild(s1);

            var s2 = new SKShapeNode();
            var p2 = new CGPath();

            p2.MoveToPoint(size / 3.0f * 2, size - size / 3.0f);
            p2.AddLineToPoint(size / 3.0f * 2, size / 4.0f);
            p2.AddLineToPoint(size / 2.0f, size / 4.0f);
            p2.AddLineToPoint(size - size / 5.0f, size / 4.0f);
            s2.Path        = p2.CopyByTransformingPath(CGAffineTransform.MakeTranslation(x * size, y * size));
            s2.StrokeColor = NSColor.Black;
            s2.FillColor   = NSColor.FromCalibratedRgba(0.0f, 0.0f, 0.0f, 0.0f);
            s2.LineWidth   = size / 20;
            AddChild(s2);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Flips the y.
        /// </summary>
        /// <param name="view">View.</param>
        private void FlipY(ImageButton button)
        {
            UIView.BeginAnimations(button.ToString());

            UIView.Animate(1, 1, UIViewAnimationOptions.CurveEaseIn, () =>
            {
                var transform = CGAffineTransform.MakeTranslation(0f, button.Frame.Height);

                if (button.IsFlipped)
                {
                    transform = CGAffineTransform.MakeScale(1.0f, 1.0f);
                }
                else
                {
                    transform = CGAffineTransform.MakeScale(1.0f, -1.0f);
                }

                button.Transform = transform;
                button.FlippedY  = !button.FlippedY;
            }, () =>
            {
            });

            UIView.CommitAnimations();
        }
Ejemplo n.º 16
0
        public void Scale()
        {
            var transform1 = CGAffineTransform.MakeTranslation(1, 2);

            // t' = t * [ sx 0 0 sy 0 0 ]
            transform1.Scale(3, 4);              // MatrixOrder.Append by default

            Assert.AreEqual((nfloat)3, transform1.xx);
            Assert.AreEqual((nfloat)0, transform1.yx);
            Assert.AreEqual((nfloat)0, transform1.xy);
            Assert.AreEqual((nfloat)4, transform1.yy);
            Assert.AreEqual((nfloat)3, transform1.x0);
            Assert.AreEqual((nfloat)8, transform1.y0);

            var transform2 = CGAffineTransform.MakeTranslation(1, 2);

            // t' = [ sx 0 0 sy 0 0 ] * t – Swift equivalent
            transform2.Scale(3, 4, MatrixOrder.Prepend);

            Assert.AreEqual((nfloat)3, transform2.xx);
            Assert.AreEqual((nfloat)0, transform2.yx);
            Assert.AreEqual((nfloat)0, transform2.xy);
            Assert.AreEqual((nfloat)4, transform2.yy);
            Assert.AreEqual((nfloat)1, transform2.x0);
            Assert.AreEqual((nfloat)2, transform2.y0);
        }
        public void SetupOrientationAndTransform()
        {
            var roi = RegionOfInterest;

            ROIToGlobalTransform = CGAffineTransform.MakeTranslation(roi.X, roi.Y);
            ROIToGlobalTransform = CGAffineTransform.Scale(ROIToGlobalTransform, roi.Width, roi.Height);
            switch (CurrentOrientation)
            {
            case UIDeviceOrientation.LandscapeLeft:
                TextOrientation     = ImageIO.CGImagePropertyOrientation.Up;
                UIRotationTransform = CGAffineTransform.MakeIdentity();
                break;

            case UIDeviceOrientation.LandscapeRight:
                TextOrientation     = ImageIO.CGImagePropertyOrientation.Down;
                UIRotationTransform = CGAffineTransform.MakeTranslation(1, 1);
                UIRotationTransform = CGAffineTransform.Rotate(UIRotationTransform, (nfloat)Math.PI);
                break;

            case UIDeviceOrientation.PortraitUpsideDown:
                TextOrientation     = ImageIO.CGImagePropertyOrientation.Left;
                UIRotationTransform = CGAffineTransform.MakeTranslation(1, 0);
                UIRotationTransform = CGAffineTransform.Rotate(UIRotationTransform, (nfloat)Math.PI / 2);
                break;

            default:
                TextOrientation     = ImageIO.CGImagePropertyOrientation.Right;
                UIRotationTransform = CGAffineTransform.MakeTranslation(0, 1);
                UIRotationTransform = CGAffineTransform.Rotate(UIRotationTransform, -(nfloat)Math.PI / 2);
                break;
            }
            VisionToAVFTransform = CGAffineTransform.Multiply(ROIToGlobalTransform, BottomToTopTransform);
            VisionToAVFTransform = CGAffineTransform.Multiply(VisionToAVFTransform, UIRotationTransform);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates the rotate flip transform given the input parameters
        /// </summary>
        /// <returns>The rotate flip transform.</returns>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="angle">Angle.</param>
        /// <param name="flipX">If set to <c>true</c> flip x.</param>
        /// <param name="flipY">If set to <c>true</c> flip y.</param>
        internal static CGAffineTransform CreateRotateFlipTransform(ref int width, ref int height, float angle, bool flipX, bool flipY)
        {
            float rotateX = (float)Math.Abs(Math.Cos(angle.ToRadians()));
            float rotateY = (float)Math.Abs(Math.Sin(angle.ToRadians()));

            float deltaWidth  = width * rotateX + height * rotateY;
            float deltaHeight = width * rotateY + height * rotateX;

            CGAffineTransform rotateFlipTransform = CGAffineTransform.MakeTranslation(flipX?-deltaWidth:0.0f, flipY?-deltaHeight:0.0f);

            rotateFlipTransform.Multiply(CGAffineTransform.MakeScale(flipX?-1.0f:1.0f, flipY?-1.0f: 1.0f));

            if (0.0f != angle)
            {
                var rot = CGAffineTransform.MakeTranslation(-deltaHeight * 0.5f, -deltaWidth * 0.5f);
                rot.Rotate(-angle.ToRadians());
                rot.Translate(deltaWidth * 0.5f, deltaHeight * 0.5f);

                rotateFlipTransform = CGAffineTransform.Multiply(rot, rotateFlipTransform);
            }

            width  = (int)deltaWidth;
            height = (int)deltaHeight;

            return(rotateFlipTransform);
        }
        /// <summary>
        /// Slides the view over time.
        /// </summary>
        /// <param name="view">View.</param>
        /// <param name="transition">Transition.</param>
        /// <param name="direction">Direction.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="onFinished">On finished.</param>
        public static void Slide(this UIView view, AnimationTransition transition, AnimationDirection direction, double duration = AnimationConstants.DefaultDuration, Action onFinished = null)
        {
            var isIn         = transition == AnimationTransition.In;
            var isLtr        = (transition == AnimationTransition.In && (direction == AnimationDirection.Down || direction == AnimationDirection.Left)) || (transition == AnimationTransition.Out && (direction == AnimationDirection.Up || direction == AnimationDirection.Right));
            var isVertical   = direction == AnimationDirection.Up || direction == AnimationDirection.Down;
            var isHorizontal = direction == AnimationDirection.Left || direction == AnimationDirection.Right;

            var minAlpha     = (nfloat)0.0f;
            var maxAlpha     = (nfloat)1.0f;
            var minTransform = CGAffineTransform.MakeTranslation(
                (isHorizontal ? (isLtr ? 1 : -1) : 0) * view.Bounds.Width,
                (isVertical ? (isLtr ? 1 : -1) : 0) * view.Bounds.Height);
            var maxTransform = CGAffineTransform.MakeIdentity();

            view.Alpha     = isIn ? minAlpha : maxAlpha;
            view.Transform = isIn ? minTransform : maxTransform;
            UIView.Animate(duration, 0, UIViewAnimationOptions.CurveEaseInOut,
                           () =>
            {
                view.Alpha     = isIn ? maxAlpha : minAlpha;
                view.Transform = isIn ? maxTransform : minTransform;
            },
                           onFinished
                           );
        }
Ejemplo n.º 20
0
        protected CGAffineTransform CreateTranslationTransform(nfloat radius, nfloat angle)
        {
            var tx = radius * (nfloat)Math.Sin(angle);
            var ty = radius * (nfloat)Math.Cos(angle);

            return(CGAffineTransform.MakeTranslation(Center.X + tx, Center.Y - ty));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Draws the specified Image at the specified location and with the specified size.
        /// </summary>
        /// <param name="image">Image.</param>
        /// <param name="rect">Rect.</param>
        public void DrawImage(Image image, RectangleF rect)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            image = GetRepresentation(context, image, rect.Size.ToSize());

            if (image.nativeMetafilePage != null)
            {
                var dst   = new CGRect(rect.X, rect.Y, rect.Width, rect.Height);
                var src   = image.nativeMetafilePage.GetBoxRect(CGPDFBox.Media);
                var scale = (nfloat)(src.Width == 0 || src.Height == 0 ? 1 : Math.Min(dst.Width / src.Width, dst.Height / src.Height));

                // Let’s not use image.nativeMetafilePage.GetDrawingTransform(), because it limits the scale to 1.0.
                var t = CGAffineTransform.MakeTranslation(-src.X, -src.Y);
                t.Scale(scale, scale);
                t.Translate(dst.X, dst.Y);

                // Flip vertically
                t.Translate(0, -dst.GetMidY());
                t.Scale(1, -1);
                t.Translate(0, dst.GetMidY());

                context.SaveState();
                context.ConcatCTM(t);
                context.DrawPDFPage(image.nativeMetafilePage);
                context.RestoreState();
            }
            else if (image.NativeCGImage != null)
            {
                DrawImage(rect, image.NativeCGImage, image.imageTransform);
            }
        }
Ejemplo n.º 22
0
        /* Returns a UIBezierPath object for the box of the checkbox
         * @returns The path of the box.
         */
        public UIBezierPath PathForBox()
        {
            UIBezierPath path;

            switch (BoxType)
            {
            case BemBoxType.BemBoxTypeSquare:
                path = UIBezierPath.FromRoundedRect(new CGRect(0, 0, Size, Size), 3);
                //[path applyTransform:CGAffineTransformRotate(CGAffineTransformIdentity, M_PI / 2)];
                path.ApplyTransform(CGAffineTransform.Rotate(CGAffineTransform.MakeIdentity(), new nfloat(Math.PI / 2)));
                path.ApplyTransform(CGAffineTransform.MakeTranslation(Size, 0));
                break;

            default:
            {
                nfloat radius = Size / 2;
                //path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.size / 2, self.size / 2)
                //                                      radius: radius
                //                                  startAngle: - M_PI / 4
                //                                    endAngle:  2 * M_PI - M_PI / 4
                //                                   clockwise:YES];

                path = UIBezierPath.FromArc(new CGPoint(Size / 2, Size / 2), radius, new nfloat(-(Math.PI / 4)), new nfloat((2 * Math.PI - Math.PI / 4)), true);
            }
            break;
            }
            return(path);
        }
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        View.AddSubview(momentumView);

        handleView.Layer.CornerRadius = 3;

        momentumView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor).Active = true;
        momentumView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor, constant: -8).Active           = true;
        momentumView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor, constant: 80).Active               = true;
        momentumView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor, constant: 80).Active = true;


        momentumView.AddSubview(handleView);
        handleView.TopAnchor.ConstraintEqualTo(momentumView.TopAnchor, constant: 10).Active = true;
        handleView.WidthAnchor.ConstraintEqualTo(50).Active = true;
        handleView.HeightAnchor.ConstraintEqualTo(5).Active = true;
        handleView.CenterXAnchor.ConstraintEqualTo(momentumView.CenterXAnchor).Active = true;

        var panRecognizer = new InstantPanGestureRecognizer();

        closedTransform        = CGAffineTransform.MakeTranslation(0, View.Bounds.Height * 0.6f);
        momentumView.Transform = closedTransform;

        panRecognizer.AddTarget(Panned);
        momentumView.AddGestureRecognizer(panRecognizer);
    }
        public override void StartInteractiveTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            base.StartInteractiveTransition(transitionContext);

            Action animation = null;

            if (IsPresenting)
            {
                toView.Frame     = transitionContext.ContainerView.Bounds;
                toView.Transform = CGAffineTransform.MakeTranslation(0, toView.Frame.Size.Height);
                transitionContext.ContainerView.AddSubview(toView);
                animation = () => toView.Transform = CGAffineTransform.MakeIdentity();
            }
            else
            {
            }

            if (WantsInteractiveStart)
            {
                animator = new UIViewPropertyAnimator(DEFAULT_DURATION, UIViewAnimationCurve.Linear, animation);
            }
            else
            {
                animator = CreateDefaultAnimator();
                animator.AddCompletion(position => transitionContext.CompleteTransition(true));
                animator.AddAnimations(animation);
                animator.StartAnimation();
            }
        }
Ejemplo n.º 25
0
    void Panned(NSObject r)
    {
        var recognizer = r as UIPanGestureRecognizer;
        var touchPoint = recognizer.LocationInView(View);

        switch (recognizer.State)
        {
        case UIGestureRecognizerState.Began:
            originalTouchPoint = touchPoint;
            break;

        case UIGestureRecognizerState.Changed:
            var offset = touchPoint.Y - originalTouchPoint.Y;
            offset = offset > 0 ? NMath.Pow(offset, 0.7f) : -NMath.Pow(-offset, 0.7f);
            rubberView.Transform = CGAffineTransform.MakeTranslation(0, offset);
            break;

        case UIGestureRecognizerState.Ended:
        case UIGestureRecognizerState.Cancelled:
            var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.6f, response: .3f);
            var animator         = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters);
            animator.AddAnimations(() => rubberView.Transform = CGAffineTransform.MakeIdentity());
            animator.Interruptible = true;
            animator.StartAnimation();
            break;

        default:
            break;
        }
    }
Ejemplo n.º 26
0
        public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration)
        {
            base.WillAnimateRotation(toInterfaceOrientation, duration);

            switch (toInterfaceOrientation)
            {
            case UIInterfaceOrientation.LandscapeLeft:
                View.Transform = CGAffineTransform.MakeRotation(0);
                View.Frame     = new CGRect(0, 0, 1024, 768);
                break;

            case UIInterfaceOrientation.LandscapeRight:
                View.Transform = CGAffineTransform.MakeRotation(0);
                View.Frame     = new CGRect(0, 0, 1024, 768);
                break;

            case UIInterfaceOrientation.Portrait:

                View.Transform = CGAffineTransform.MakeTranslation(128, 0);
                View.Transform = CGAffineTransform.MakeRotation((nfloat)Math.PI / 2);
                View.Frame     = new CGRect(0, 0, 768, 1024);
                break;

            case UIInterfaceOrientation.PortraitUpsideDown:
                View.Transform = CGAffineTransform.MakeTranslation(128, 0);
                View.Transform = CGAffineTransform.MakeRotation((nfloat)Math.PI / 2);
                View.Frame     = new CGRect(0, 0, 768, 1024);
                break;
            }
        }
Ejemplo n.º 27
0
        CGAffineTransform CGAffineTransformMakeSkew(nfloat skewAmount, nfloat height)
        {
            CGAffineTransform skewTransform = CGAffineTransform.MakeIdentity();

            skewTransform    = CGAffineTransform.MakeTranslation((nfloat)skewAmount * height / 2, 0);
            skewTransform.xy = skewAmount;
            return(skewTransform);
        }
Ejemplo n.º 28
0
        private static CGAffineTransform CreateAffineTransform(double rotation, Point position)
        {
            var transformTranslate = CGAffineTransform.MakeTranslation((float)position.X, (float)position.Y);
            var transformRotate    = CGAffineTransform.MakeRotation((float)(rotation * RadiansPerDegree));
            var transform          = transformRotate * transformTranslate;

            return(transform);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Centers the viewport around the specified position (x-index and y-value) in the chart.
        /// Centering the viewport outside the bounds of the chart is not possible.
        /// Makes most sense in combination with the setScaleMinima(...) method.
        /// </summary>
        public void CenterViewPort(CGPoint pt, IChartBase chart)
        {
            var translateX = pt.X - OffsetLeft;
            var translateY = pt.Y - OffsetTop;
            var matrix     = touchMatrix * CGAffineTransform.MakeTranslation(-translateX, -translateY);

            Refresh(matrix, chart: chart, invalidate: true);
        }
Ejemplo n.º 30
0
        private static CGAffineTransform CalculateAffineTransform(CGRect sourceRect, CGRect targetRect)
        {
            var transform = CGAffineTransform.MakeTranslation(targetRect.X - sourceRect.X,
                                                              targetRect.Y - sourceRect.Y);

            transform.Scale(targetRect.Width / sourceRect.Width,
                            targetRect.Height / sourceRect.Height);
            return(transform);
        }