Example #1
0
        static UIImage imageWithPDFPage(CGPDFPage page, float scale, CGAffineTransform t)
        {
            if (page == null)
            {
                return(null);
            }

            RectangleF box = page.GetBoxRect(CGPDFBox.Crop);

            t.Scale(scale, scale);
            box = new RectangleF(box.Location, new SizeF(box.Size.Width * scale, box.Size.Height * scale));

            var          pixelWidth = box.Size.Width;
            CGColorSpace cs         = CGColorSpace.CreateDeviceRGB();
            //DebugAssert( cs ) ;
            var _buffer = Marshal.AllocHGlobal((int)(box.Width * box.Height));

            UIGraphics.BeginImageContext(box.Size);
            CGContext c = UIGraphics.GetCurrentContext();

            c.SaveState();
            c.TranslateCTM(0f, box.Height);
            c.ScaleCTM(1f, -1f);
            cs.Dispose();
            c.ConcatCTM(t);
            c.DrawPDFPage(page);

            c.RestoreState();
            var image = UIGraphics.GetImageFromCurrentImageContext();

            return(image);
        }
Example #2
0
        /// <summary>
        /// Shows the menu from controller.
        /// </summary>
        /// <param name="viewController">View controller.</param>
        public void ShowMenuFromController(UIViewController viewController)
        {
            if (this.DoneAnimations)
            {
                return;
            }

            this.NavController = JVMenuHelper.TopViewController();

            this.CurrentController = viewController;

            var currFrame = MenuView.Frame;

            var newFrame = this.View.Frame;

            UIView.AnimateNotify(0.15f, () =>
            {
                if (this.NavController != this.CurrentController)
                {
                    this.CurrentController.View.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 0.6f, 0.6f);
                }
            }, (bool finished) =>
            {
                if (finished)
                {
                    this.Image = JVMenuHelper.TakeScreenShotOfView(this.NavController.View, false);

                    this.View.BackgroundColor = UIColor.FromPatternImage(this.Image);

                    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                    {
                        if (!UIAccessibility.IsReduceTransparencyEnabled)
                        {
                            //VibrancyEffectView.ContentView.Add(MenuView);
                            //VibrancyEffectView.ContentView.Add(CloseBtn);
                            //BlurEffectView.ContentView.Add(VibrancyEffectView);

                            this.View.InsertSubview(BlurEffectView, 0);
                        }
                    }

                    this.DoneAnimations = true;
                    this.CloseBtn.Alpha = 0.0f;
                    this.MenuView.Alpha = 0.0f;

                    this.NavController.PresentViewController(this, false, () =>
                    {
                        UIView.Animate(0.15f, 0.0f, UIViewAnimationOptions.CurveEaseInOut, () =>
                        {
                            this.CloseBtn.Alpha = 1.0f;
                            this.MenuView.Alpha = 1.0f;

                            this.MenuView.TableView.ReloadData();
                        }, null);
                    });
                }
            });

            UIApplication.SharedApplication.SetStatusBarHidden(true, UIStatusBarAnimation.Fade);
        }
Example #3
0
 public virtual void WillShowViewController(UINavigationController navigationController, UIViewController viewController, bool animated)
 {
     UIView.Animate(0.3f / 1.5f, () =>
     {
         viewController.View.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 1.0f, 1.0f);
     });
 }
Example #4
0
        /// <summary>
        /// Creates native transform which applies multiple transformations in this order:
        /// Scale(ScaleX, ScaleY )
        /// Skew(SkewX, SkewY)
        /// Rotate(Rotation)
        /// Translate(TranslateX, TranslateY)
        /// https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.compositetransform.aspx
        /// </summary>
        /// <returns></returns>
        internal override CGAffineTransform ToNativeTransform(CGSize size, bool withCenter = true)
        {
            var pivotX = withCenter ? CenterX : 0;
            var pivotY = withCenter ? CenterY : 0;

            var transform = CGAffineTransform.MakeIdentity();

            //Perform transformations about centre
            transform = CGAffineTransform.Translate(transform, (float)(pivotX), (float)(pivotY));

            //Apply transformations in order
            transform = CGAffineTransform.Scale(transform, (float)ScaleX, (float)ScaleY);

            //TODO: implement skew (see eg http://stackoverflow.com/questions/6203738/iphone-skew-a-calayer)
            if ((SkewX != 0 || SkewY != 0) && this.Log().IsEnabled(LogLevel.Warning))
            {
                this.Log().Warn("Skew is not enabled for CompositeTransform.");
            }

            transform = CGAffineTransform.Rotate(transform, (nfloat)ToRadians(Rotation));

            transform = CGAffineTransform.Translate(transform, (float)TranslateX, (float)TranslateY);

            //Unapply centering
            transform = CGAffineTransform.Translate(transform, (float)(-pivotX), (float)(-pivotY));

            return(transform);
        }
Example #5
0
        /// <summary>
        /// Closes the menu from controller.
        /// </summary>
        /// <param name="viewController">View controller.</param>
        public void CloseMenuFromController(UIViewController viewController)
        {
            // if we haven't finished show menu animations then return to avoid overlaps or interruptions
            if (!this.DoneAnimations)
            {
                return;
            }

            UIView.Animate(0.3f / 1.5f, () =>
            {
                this.CurrentController.View.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 1.0f, 1.0f);
            }, () =>
            {
                this.DoneAnimations = false;

                UIApplication.SharedApplication.SetStatusBarHidden(false, UIStatusBarAnimation.Fade);

                this.NavController.DismissViewController(false, () =>
                {
                    if (this.NavController != this.CurrentController)
                    {
                        this.CurrentController.DismissViewController(false, null);
                    }
                });
            });
        }
Example #6
0
        private void HandleOnGestureRecognizer(UIPanGestureRecognizer gestureRecognizer)
        {
            // The translation of the pan gesture in the coordinate system of the specified view.
            var xTranslation = gestureRecognizer.TranslationInView(this).X;
            var yTranslation = gestureRecognizer.TranslationInView(this).Y;

            if (gestureRecognizer.State.Equals(UIGestureRecognizerState.Began))
            {
                _startingPoint = Center;
            }
            else if (gestureRecognizer.State.Equals(UIGestureRecognizerState.Changed))
            {
                var rotationStrength = Math.Min(xTranslation / RotationStrength, 1);
                var rotationAngle    = (nfloat)(2 * Math.PI * rotationStrength / 17);
                var scaleStrength    = 1 - Math.Abs(rotationStrength) / 4;
                var scale            = (nfloat)Math.Max(scaleStrength, ScaleStrength);
                var transform        = CGAffineTransform.MakeRotation(rotationAngle);

                Center    = new CGPoint(_startingPoint.X + xTranslation, _startingPoint.Y + yTranslation);
                Transform = CGAffineTransform.Scale(transform, scale, scale);
            }
            else if (gestureRecognizer.State.Equals(UIGestureRecognizerState.Ended))
            {
                DetermineSwipeAction(xTranslation);
                ResetView();
            }
        }
Example #7
0
        private void WillDisplayCell(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
        {
            if (this.DoneCellAnimations)
            {
                return;
            }

            var oldFrame = cell.Frame;
            var newFrame = new CGRect(-cell.Frame.Size.Width, cell.Frame.Top, 0, cell.Frame.Size.Height);

            var velocity = cell.Frame.Size.Width / 100;

            cell.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 0.95f, 0.0001f);
            cell.Frame     = newFrame;

            UIView.AnimateNotify(0.3f / 1.5f, 0.05f * indexPath.Row, 0.67f, velocity, UIViewAnimationOptions.TransitionNone, () =>
            {
                cell.Frame     = oldFrame;
                cell.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 1.0f, 1.0f);
            }, (finished) =>
            {
                var rows = TableView.NumberOfRowsInSection(0);

                if (rows == indexPath.Row + 1)
                {
                    DoneCellAnimations = true;
                }
            });
        }
        private void SetUI()
        {
            var photosFileSystemService = new FoodMarkerPhotosFileSystemService(_foodMarker);

            photosFileSystemService.UploadFoodMarkerPhotosToDir();

            _scrollViewBuilder.Width  = View.Frame.Width;
            _scrollViewBuilder.Height = View.Frame.Height;
            _scrollViewBuilder.Load(_foodMarker.FoodName);
            m_PartialTransform = _scrollViewBuilder.FoodNameControl.Transform;
            m_FullTransform    = CGAffineTransform.Scale(_scrollViewBuilder.FoodNameControl.Transform, 1.3f, 1.3f);

            _contentViewBuilder.Width  = View.Frame.Width;
            _contentViewBuilder.Y      = m_ContentViewYInit;
            _contentViewBuilder.X      = 0;
            _contentViewBuilder.Height = 0;
            _contentViewBuilder.Load();

            foreach (IBottomSheetContainerView container in _containerList)
            {
                container.Load(_foodMarker);
            }

            _contentViewBuilder.Height = _containerList[_containerList.Count - 1].View.Frame.GetMaxY();
            _contentViewBuilder.Load();

            _scrollViewBuilder.SetContentSize(View.Frame.Width, ContentView.Frame.Height);
        }
        public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
        {
            if (previousTraitCollection == null)
            {
                previousTraitCollection = new UITraitCollection();
            }

            base.TraitCollectionDidChange(previousTraitCollection);

            if (TraitCollection.VerticalSizeClass == UIUserInterfaceSizeClass.Compact)
            {
                CGAffineTransform t = CGAffineTransform.MakeIdentity();
                t.Translate(this.Frame.Width / 2, 0);
                t.Scale(0.5f, 0.5f);

                this.Transform = t;
            }
            else
            {
                CGAffineTransform t = CGAffineTransform.MakeIdentity();
                t.Translate(0, 0);
                t.Scale(1f, 1f);

                this.Transform = t;
            }
        }
        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);
        }
Example #11
0
        // rect changes depending on if the whole view is being redrawn, or just a section
        public override void Draw(RectangleF rect)
        {
            Console.WriteLine("Draw() Called");
            base.Draw(rect);

            // get a reference to the context
            using (CGContext context = UIGraphics.GetCurrentContext()) {
                // convert to View space
                CGAffineTransform affineTransform = CGAffineTransform.MakeIdentity();
                // invert the y axis
                affineTransform.Scale(1, -1);
                // move the y axis up
                affineTransform.Translate(0, Frame.Height);
                context.ConcatCTM(affineTransform);

                // draw our coordinates for reference
                DrawCoordinateSpace(context);

                // draw our flag
                DrawFlag(context);

                // add a label
                DrawCenteredTextAtPoint(context, 384, 700, "Stars and Stripes", 60);
            }
        }
Example #12
0
        public void ZoomTo(nfloat newScale, CGPoint newAnchor)
        {
            // Figure out what the final scale will be after this transform.
            var targetScale = cumulativeScale * newScale;

            // If it's less than 1, we don't allow that at this point, so we constrain it to 1.0.
            if (targetScale < 1.0f)
            {
                newScale = 1.0f / cumulativeScale;
            }

            // Scale and translate the last transform.
            lastTransform.Scale(newScale, newScale);
            lastTransform.Translate(-GetZoomOffsetX(newScale, newAnchor), -GetZoomOffsetY(newScale, newAnchor));

            // Update the cumulative scale.
            cumulativeScale *= newScale;

            // Constrain the plot to the bounds of the chart using the new cumulative scale.
            lastTransform = ConstrainTransformToBounds(lastTransform, cumulativeScale);

            // Update the ploat transform.
            plotTransform = lastTransform;
            UpdatePlot();
        }
Example #13
0
        static UIImage imageWithPDFPage(CGPDFPage page, float scale ,CGAffineTransform t )
        {
            if (page == null)
            {
                return null ;
            }

            RectangleF box = page.GetBoxRect(CGPDFBox.Crop);

            t.Scale(scale,scale);
            box = new RectangleF(box.Location,new SizeF(box.Size.Width * scale, box.Size.Height * scale));

            var pixelWidth = box.Size.Width ;
            CGColorSpace cs = CGColorSpace.CreateDeviceRGB() ;
            //DebugAssert( cs ) ;
            var _buffer = Marshal.AllocHGlobal((int)(box.Width * box.Height));
            UIGraphics.BeginImageContext(box.Size);
            CGContext c = UIGraphics.GetCurrentContext();
            cs.Dispose();
            c.ConcatCTM(t);
            c.DrawPDFPage(page);

            var image = UIGraphics.GetImageFromCurrentImageContext();
            return image ;
        }
        /// <summary>
        /// Draws our animation path on the background image, just to show it
        /// </summary>
        protected void DrawPathAsBackground()
        {
            //---- create our offscreen bitmap context
            // size
            SizeF bitmapSize = new SizeF(this.View.Frame.Size);

            using (CGBitmapContext context = new CGBitmapContext(IntPtr.Zero
                                                                 , (int)bitmapSize.Width, (int)bitmapSize.Height, 8
                                                                 , (int)(4 * bitmapSize.Width), CGColorSpace.CreateDeviceRGB()
                                                                 , CGImageAlphaInfo.PremultipliedFirst))
            {
                //---- convert to View space
                CGAffineTransform affineTransform = CGAffineTransform.MakeIdentity();
                //---- invert the y axis
                affineTransform.Scale(1, -1);
                //---- move the y axis up
                affineTransform.Translate(0, this.View.Frame.Height);
                context.ConcatCTM(affineTransform);

                //---- actually draw the path
                context.AddPath(this._animationPath);
                context.SetStrokeColorWithColor(UIColor.LightGray.CGColor);
                context.SetLineWidth(3);
                context.StrokePath();

                //---- set what we've drawn as the backgound image
                this._backgroundImage.Image = UIImage.FromImage(context.ToImage());
            }
        }
        UIImage ForceImagePortrait(UIImage image)
        {
            const float M_PI = 3.14159265359f;

            CGAffineTransform rectTransform = CGAffineTransform.MakeIdentity();

            switch (image.Orientation)
            {
            case UIImageOrientation.Left:
                rectTransform = CGAffineTransform.Translate(CGAffineTransform.MakeRotation(M_PI * 2), 0, -image.Size.Height);
                break;

            case UIImageOrientation.Right:
                rectTransform = CGAffineTransform.Translate(CGAffineTransform.MakeRotation(-(M_PI * 2)), -image.Size.Width, 0);
                break;

            case UIImageOrientation.Down:
                rectTransform = CGAffineTransform.Translate(CGAffineTransform.MakeRotation(-M_PI), -image.Size.Width,
                                                            -image.Size.Height);
                break;
            }
            ;
            rectTransform = CGAffineTransform.Scale(rectTransform, image.CurrentScale, image.CurrentScale);

            image.CGImage.WithImageInRect(CGAffineTransform.CGRectApplyAffineTransform(
                                              new RectangleF(0, 0, image.Size.Width, image.Size.Height), rectTransform));

            var portraitImage = UIImage.FromImage(image.CGImage, image.CurrentScale, image.Orientation);

            return(portraitImage);
        }
 static void Anumate(UIButton button)
 {
     UIView.Animate(0.2, () => {
         button.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 2f, 2f);
     }, () => {
         button.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), (nfloat)1f, (nfloat)1f);
     });
 }
        CGAffineTransform CreateScaleTransform(CGAffineTransform currentTransform)
        {
            var flip  = UIApplication.SharedApplication.StatusBarOrientation.IsLandscape();
            var scale = flip ? 2.0f : 2.5f;

            currentTransform.Scale(scale, scale);

            return(currentTransform);
        }
Example #18
0
        protected override void OnElementChanged(ElementChangedEventArgs <Label> e)
        {
            base.OnElementChanged(e);
            StretchedLabel    label = (StretchedLabel)e.NewElement;
            CGAffineTransform old   = Control.Transform;
            CGAffineTransform t     = new CGAffineTransform(old.xx, old.yx, old.xy, old.yy, old.x0, old.y0);

            t.Scale(label.Factor, 1);
            Control.Transform = t;
        }
        public void StaticScale()
        {
            var transformM = CGAffineTransform.Scale(CGAffineTransform.MakeTranslation(0, 200), 1, -1);
            var transformN = CGAffineTransformScale(CGAffineTransform.MakeTranslation(0, 200), 1, -1);

            Assert.IsTrue(transformM == transformN, "1");

            transformM = CGAffineTransform.Scale(CGAffineTransform.MakeTranslation(1, 2), -3, -4);
            transformN = CGAffineTransformScale(CGAffineTransform.MakeTranslation(1, 2), -3, -4);

            Assert.IsTrue(transformM == transformN, "2");
        }
        private void AnimateZoomInAtPoint(CGPoint touchPoint)
        {
            const float GROW_ANIMATION_DURATION_SECONDS = 0.15f;

            UIView.BeginAnimations(null);
            UIView.SetAnimationDuration(GROW_ANIMATION_DURATION_SECONDS);
            UIView.SetAnimationDelegate(this);
            UIView.SetAnimationDidStopSelector(new Selector("zoomInAnimationDidStop:numFinished:context:"));

            CGPoint           translate = CalculateTranslationForScale(touchPoint, SCALE);
            CGAffineTransform transform = CGAffineTransform.MakeTranslation(translate.X, translate.Y);

            transform = CGAffineTransform.Scale(transform, SCALE, SCALE);

            this.Transform = transform;

            UIView.CommitAnimations();
        }
Example #21
0
        internal override CGAffineTransform ToNativeTransform(CGSize size, bool withCenter = true)
        {
            var pivotX = withCenter ? CenterX : 0;
            var pivotY = withCenter ? CenterY : 0;

            var transform = CGAffineTransform.MakeIdentity();

            //Perform transformations about centre
            transform = CGAffineTransform.Translate(transform, (nfloat)pivotX, (nfloat)pivotY);

            //Apply transformations in order
            transform = CGAffineTransform.Scale(transform, (nfloat)ScaleX, (nfloat)ScaleY);

            //Unapply centering
            transform = CGAffineTransform.Translate(transform, -(nfloat)pivotX, -(nfloat)pivotY);

            return(transform);
        }
Example #22
0
        /// <summary>
        /// Did pick the item
        /// </summary>
        /// <param name="item">Item.</param>
        public virtual void DidPickItem(UINavigationController navController, JVMenuItem item)
        {
            if (item is JVMenuActionItem &&
                ((JVMenuActionItem)item).Command != null)
            {
                this.BeginInvokeOnMainThread(((JVMenuActionItem)item).Command);
            }
            else if (item is JVMenuViewControllerItem &&
                     ((JVMenuViewControllerItem)item).HasViewController)
            {
                var aVC = ((JVMenuViewControllerItem)item).ViewController;

                if (aVC != menuController.CurrentController)
                {
                    aVC.View.Transform            = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 0.6f, 0.6f);
                    navController.ViewControllers = new UIViewController[] { aVC };
                }
            }
        }
        private void UpdateSquareTransform(CGPoint translation, nfloat rotation, nfloat scale)
        {
            var transform = CGAffineTransform.MakeIdentity();

            Console.WriteLine(lastScale);

            // Include previous translation, rotation and scale
            translation.X += lastTranslation.X;
            translation.Y += lastTranslation.Y;
            rotation      += lastRotation;
            scale         *= lastScale;

            // Combine translation, rotation and scale
            transform = CGAffineTransform.Translate(transform, translation.X, translation.Y);
            transform = CGAffineTransform.Rotate(transform, rotation);
            transform = CGAffineTransform.Scale(transform, scale, scale);

            square.Transform = transform;
        }
        // rect changes depending on if the whole view is being redrawn, or just a section
        public override void Draw(RectangleF rect)
        {
            Console.WriteLine("Draw() Called");
            base.Draw(rect);

            // get a reference to the context
            using (CGContext context = UIGraphics.GetCurrentContext()) {
                // convert to View space
                CGAffineTransform affineTransform = CGAffineTransform.MakeIdentity();
                // invert the y axis
                affineTransform.Scale(1, -1);
                // move the y axis up
                affineTransform.Translate(0, Frame.Height);
                context.ConcatCTM(affineTransform);

                // draw some stars
                DrawStars(context);
            }
        }
Example #25
0
        void RestoreViewFromTestAgainstNative()
        {
            InvokeOnMainThread(delegate
            {
                _nativeWord.ShrinkWord();
                CGAffineTransform transform = CGAffineTransform.MakeIdentity();
                transform.Scale(1f, 1f);

                UIView.Animate(0.5, 0, UIViewAnimationOptions.TransitionCurlUp,
                               () =>
                {
                    _nativeWord.Frame     = new CGRect(0, 0, 320, 30);
                    _targetWord.Transform = transform;
                }, () =>
                {
                    btnSkipTimer.SetTitle("", UIControlState.Normal);
                    btnSkipTimer.BackgroundColor = "1ECE6D".ToUIColor();
                });
            });
        }
        protected void ScaleView()
        {
            if (ScalingEnabled && MinScale.HasValue && MaxScale.HasValue)
            {
                float scale = (float)(1 - -_scrollView.ContentOffset.Y / _scrollViewRaisingOffset * (MaxScale.Value - MinScale.Value));

                if (scale > MaxScale.Value)
                {
                    scale = MaxScale.Value;
                }
                else if (scale < MinScale.Value)
                {
                    scale = MinScale.Value;
                }

                CGAffineTransform transform = CGAffineTransform.MakeIdentity();
                transform            = CGAffineTransform.Scale(transform, scale, scale);
                _stackView.Transform = transform;
            }
        }
Example #27
0
        void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(ViewModel.MessageSent))
            {
                UIView.Animate(1, 0, UIViewAnimationOptions.CurveLinear,
                               () =>
                {
                    envelopeImage.Center =
                        new CGPoint(UIScreen.MainScreen.Bounds.Right - envelopeImage.Frame.Width / 2,
                                    UIScreen.MainScreen.Bounds.Top + envelopeImage.Frame.Height / 2);

                    envelopeImage.Transform = CGAffineTransform.Scale(envelopeImage.Transform, 0.5f, 0.5f);
                },
                               () =>
                {
                    ViewModel.ExitCommand.Execute();
                }
                               );
            }
        }
Example #28
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);
        }
Example #29
0
        void modifiedGesture(UIGestureRecognizer gesture)
        {
            if (gesture.GetType() == typeof(UIPinchGestureRecognizer))
            {
                var pinch = (UIPinchGestureRecognizer)gesture;
                scaleTransform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), pinch.Scale, pinch.Scale);
            }
            else if (gesture.GetType() == typeof(UIRotationGestureRecognizer))
            {
                var rotate = (UIRotationGestureRecognizer)gesture;
                rotateTransform = CGAffineTransform.Rotate(CGAffineTransform.MakeIdentity(), rotate.Rotation);
            }
            else if (gesture.GetType() == typeof(UIPanGestureRecognizer))
            {
                var     pan         = (UIPanGestureRecognizer)gesture;
                CGPoint translation = pan.TranslationInView(Superview);
                panTransform = CGAffineTransform.Translate(CGAffineTransform.MakeIdentity(), translation.X, translation.Y);
            }

            Transform = CGAffineTransform.Multiply(CGAffineTransform.Multiply(scaleTransform, rotateTransform), panTransform);
        }
Example #30
0
        void ShowViewWithAnimation()
        {
            var topLeft  = this.GetCenter(CanvasView.Frame);
            var topRight = new CGPoint(topLeft.X + CanvasView.Frame.Width, topLeft.Y);

            CanvasView.Frame             = new CGRect(topLeft, CanvasView.Frame.Size);
            CanvasView.Layer.BorderWidth = 2;
            CanvasView.Layer.BorderColor = UIColor.FromRGB(42, 56, 93).CGColor;
            CanvasView.Transform         = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 0.001f, 0.001f);
            Add(CanvasView);

            AnimateAsync(0.2, () => {
                CanvasView.Transform = CGAffineTransform.Scale(CGAffineTransform.MakeIdentity(), 1, 1);
            });

            CancelButton.SizeToFit();
            CancelButton.Frame = new CGRect(new CGPoint(topLeft.X + 10, topLeft.Y - 40), CancelButton.Frame.Size);
            Add(CancelButton);
            Add(OkButton);
            OkButton.SizeToFit();
            OkButton.Frame = new CGRect(new CGPoint(topRight.X - OkButton.Frame.Width - 10, topRight.Y - 40), OkButton.Frame.Size);
        }
        private void AnimateOpening(double duration = 0)
        {
            if (_isOpened)
            {
                return;
            }
            _isOpened = true;

            if (_wasResized || _hintLabel.Frame.Height == 0)
            {
                _hintLabel.Superview.SetNeedsLayout();
                _hintLabel.Superview.LayoutIfNeeded();
                _wasResized = false;
            }

            AnimateNotify(
                duration,
                () =>
            {
                var initialTransform    = _hintLabel.Transform;
                var scaledTransform     = CGAffineTransform.Scale(initialTransform, HintLabelScale, HintLabelScale);
                var translatedTransform = CGAffineTransform.Translate(
                    scaledTransform,
                    -((Frame.Width - _hintLabel.Frame.Width * HintLabelScale) / 2 / HintLabelScale),
                    -(((Frame.Height * HintLabelOffsetMultiplier - _hintLabel.Frame.Height * HintLabelScale) / 2 +
                       _hintLabel.Frame.Height * HintLabelScale) / HintLabelScale));
                _hintLabel.Transform = translatedTransform;
            },
                completed =>
            {
                if (!completed)
                {
                    return;
                }
                BackgroundColor = _backgroundColor;
            });
        }
        /// <summary>
        /// Draws the specified portion of the specified Image at the specified location and with the specified size.
        /// 
        /// The destPoints specifies a parallelogram with the first point specifying the upper left corner, 
        /// second point specifying the upper right corner and the third point specifying the lower left corner.
        /// 
        /// The srcRect parameter specifies a rectangular portion of the image object to draw. This portion is scaled 
        /// up or down (in the case where source rectangle overruns the bounds of the image) to fit inside the rectangle 
        /// specified by the destRect parameter.  
        /// </summary>
        /// <param name="image">Image.</param>
        /// <param name="destPoints">Destination points.</param>
        /// <param name="srcRect">Source rect.</param>
        /// <param name="srcUnit">Source unit.</param>
        public void DrawImage(Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
        {
            if (image == null)
                throw new ArgumentNullException ("image");
            if (destPoints == null)
                throw new ArgumentNullException ("destPoints");

            if (destPoints.Length < 3)
                throw new ArgumentException ("Destination points must be an array with a length of 3 or 4. " +
                                             "A length of 3 defines a parallelogram with the upper-left, upper-right, " +
                                             "and lower-left corners. A length of 4 defines a quadrilateral with the " +
                                             "fourth element of the array specifying the lower-right coordinate.");

            // Windows throws a Not Implemented error if the points are more than 3
            if (destPoints.Length > 3)
                throw new NotImplementedException ();

            var srcRect1 = srcRect;

            // If the source units are not the same we need to convert them
            // The reason we check for Pixel here is that our graphics already has the Pixel's baked into the model view transform
            if (srcUnit != graphicsUnit && srcUnit != GraphicsUnit.Pixel)
            {
                ConversionHelpers.GraphicsUnitConversion (srcUnit, graphicsUnit, image.HorizontalResolution, image.VerticalResolution,  ref srcRect1);
            }

            // Obtain the subImage
            var subImage = image.NativeCGImage.WithImageInRect (srcRect1.ToCGRect ());

            // If we do not have anything to draw then we exit here
            if (subImage.Width == 0 || subImage.Height == 0)
                return;

            // create our rectangle.  Offset is 0 because the CreateGeometricTransform bakes our x,y offset in there.
            var rect = new RectangleF (0,0, destPoints [1].X - destPoints [0].X, destPoints [2].Y - destPoints [0].Y);

            // We need to flip our Y axis so the image appears right side up
            var geoTransform = new CGAffineTransform (1, 0, 0, -1, 0, rect.Height);

            // Make sure we scale the image in case the source rectangle
            // overruns our subimage bounds (width and/or height)
            float scaleX = subImage.Width/srcRect1.Width;
            float scaleY = subImage.Height/srcRect1.Height;
            geoTransform.Scale (scaleX, scaleY);

            //var geott = GeomUtilities.CreateGeometricTransform (rect, destPoints);
            geoTransform.Multiply (GeomUtilities.CreateGeometricTransform (rect, destPoints));

            // Apply our transform to the context
            context.ConcatCTM (geoTransform);

            // now we draw our image.
            context.DrawImage(rect.ToCGRect (), subImage);

            // Now we revert our image transform from the context
            var revert = CGAffineTransform.CGAffineTransformInvert (geoTransform);
            context.ConcatCTM (revert);
        }
Example #33
0
        private CGAffineTransform NodeToParentTransform()
        {
            if (_isTransformDirty) {
                _transform = CGAffineTransform.MakeIdentity();

                if (!IsRelativeAnchorPoint) {
                    _transform.Translate(TransformAnchor.X, TransformAnchor.Y);
                }

                _transform.Translate((int)Position.X, (int)Position.Y);
                _transform.Rotate(Rotation.ToRadians());
                _transform.Scale(ScaleX, ScaleY);
                _transform.Translate(-TransformAnchor.X, -TransformAnchor.Y);

                _isTransformDirty = false;
            }

            return _transform;
        }