コード例 #1
0
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(CGRect rect)
        {
            var array       = base.LayoutAttributesForElementsInRect(rect);
            var visibleRect = new CGRect(CollectionView.ContentOffset, CollectionView.Bounds.Size);

            int collectionViewCount = (int)this.CollectionView.NumberOfItemsInSection(0);

            foreach (var attributes in array)
            {
                if (collectionViewCount == 1)
                {
                    float zoom = 1 + ZOOM_FACTOR;
                    attributes.Transform3D = CATransform3D.MakeScale(zoom, zoom, 1.0f);
                    attributes.ZIndex      = 1;
                }
                if (attributes.Frame.IntersectsWith(rect) && (collectionViewCount != 2 && collectionViewCount != 3))
                {
                    float distance           = (float)(visibleRect.GetMidX() - attributes.Center.X);
                    float normalizedDistance = distance / ACTIVE_DISTANCE;
                    if (Math.Abs(distance) < ACTIVE_DISTANCE)
                    {
                        float zoom = 1 + ZOOM_FACTOR * (1 - Math.Abs(normalizedDistance));
                        attributes.Transform3D = CATransform3D.MakeScale(zoom, zoom, 1.0f);
                        attributes.ZIndex      = 1;
                    }
                }
            }
            return(array);
        }
コード例 #2
0
        /// <summary>
        /// Show the Modal Picker.
        /// </summary>
        /// <param name="title">Window Title.</param>
        /// <param name="doneButtonTitle">Done button title.</param>
        /// <param name="cancelButtonTitle">Cancel button title.</param>
        /// <param name="callback">Callback that return selected value in Picker.</param>
        public void Show(string title, string doneButtonTitle, string cancelButtonTitle, Action <K> callback)
        {
            this.OnValueSelected = callback;
            this.titleLabel.Text = title;
            this.doneButton?.SetTitle(doneButtonTitle, UIControlState.Normal);

            if (this.showCancelButton)
            {
                this.cancelButton.SetTitle(cancelButtonTitle, UIControlState.Normal);
            }

            var del    = UIApplication.SharedApplication.Delegate;
            var window = del.GetWindow();

            window.AddSubview(this);
            window.BringSubviewToFront(this);
            window.EndEditing(true);

            NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIDeviceOrientationDidChangeNotification"), (NSNotification obj) => {
                CGSize screenSize = this.CountScreenSize();
                CGSize dialogSize = new CGSize(300, 230 + kDefaultButtonHeight + kDefaultButtonSpacerHeight);

                this.Frame       = new CGRect(0, 0, screenSize.Width, screenSize.Height);
                dialogView.Frame = new CGRect((screenSize.Width - dialogSize.Width) / 2.0, (screenSize.Height - dialogSize.Height) / 2.0, dialogSize.Width, dialogSize.Height);
            });


            Animate(0.2, 0.0, UIViewAnimationOptions.CurveEaseInOut, () =>
            {
                this.BackgroundColor            = UIColor.FromRGBA(0, 0, 0, (nfloat)0.4);
                this.dialogView.Layer.Opacity   = 1;
                this.dialogView.Layer.Transform = CATransform3D.MakeScale(1, 1, 1);
            }, () => { });
        }
コード例 #3
0
        public void HideAnimated(bool animated, Action completion)
        {
            CATransaction.Begin();
            {
                CATransaction.CompletionBlock = () =>
                {
                    completion?.Invoke();
                    Layer.Transform = CATransform3D.Identity;
                };

                if (animated)
                {
                    Layer.AnimateKey(new NSString("transform"), null,
                                     NSValue.FromCATransform3D(CATransform3D.MakeScale(0.5f, 0.5f, 1)),
                                     (animation) =>
                    {
                        animation.Duration       = 0.55;
                        animation.TimingFunction = CAMediaTimingFunction.FromControlPoints(0.1f, -2, 0.3f, 3);
                    });
                    Layer.AnimateKey(new NSString("opacity"), null,
                                     NSObject.FromObject(0.0), (animation) =>
                    {
                        animation.Duration = 0.75;
                    });
                }
                else                 // not animated - just set opacity to 0.0
                {
                    Layer.Opacity = 0.0f;
                }
            }
            CATransaction.Commit();
        }
コード例 #4
0
        public void animation2(Button button)
        {
            var scaleAnimation = CABasicAnimation.FromKeyPath("transform");

            scaleAnimation.From = NSValue.FromCATransform3D(CATransform3D.MakeScale(1, 1, 1));
            scaleAnimation.To   = NSValue.FromCATransform3D(CATransform3D.MakeScale(2, 2, 1));


            var opacityAnimation = CABasicAnimation.FromKeyPath("opacity");

            opacityAnimation.From = NSNumber.FromFloat(0.25f);
            opacityAnimation.To   = NSNumber.FromFloat(0.0f);

            var rippleAnimationGroup = new CAAnimationGroup
            {
                Duration            = 2.0f,
                TimeOffset          = -0.25f,
                RemovedOnCompletion = true,
                FillMode            = CAFillMode.Both,
                TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut),
                Animations          = new CAAnimation[] { scaleAnimation, opacityAnimation }
            };


            rippleCircleLayer.AddAnimation(rippleAnimationGroup, "rippleMyAnimations");
        }
コード例 #5
0
        /// <summary>
        /// Close the Modal Window and removes it from Super View
        /// </summary>
        public void Close()
        {
            NSNotificationCenter.DefaultCenter.RemoveObserver(this, "UIDeviceOrientationDidChangeNotification", null);
            CATransform3D currentTransform = this.dialogView.Layer.Transform;

            nfloat        startRotation = nfloat.Parse(this.ValueForKeyPath(new NSString("layer.transform.rotation.z")).ToString());
            CATransform3D rotation      = CATransform3D.MakeRotation((nfloat)(-startRotation + Math.PI * 270 / 180), 0, 0, 0);

            CATransform3D scale = CATransform3D.MakeScale((nfloat)1, (nfloat)1, 1);

            this.dialogView.Layer.Transform = currentTransform.Concat(scale);
            this.dialogView.Layer.Opacity   = 1;

            UIView.Animate(0.2, 0, UIViewAnimationOptions.TransitionNone, () =>
            {
                this.BackgroundColor            = UIColor.FromRGBA(0, 0, 0, 0);
                this.dialogView.Layer.Transform = currentTransform.Concat(CATransform3D.MakeScale((nfloat)0.6, (nfloat)0.6, 1));
                this.dialogView.Layer.Opacity   = 0;
            }, () =>
            {
                foreach (UIView v in this.Subviews)
                {
                    v.RemoveFromSuperview();
                }

                this.RemoveFromSuperview();
                this.SetupViews();
            });
        }
コード例 #6
0
        void floatLabelToTop(bool changeColor = true)
        {
            CATransaction.Begin();
            CATransaction.CompletionBlock = () => {
                if (changeColor)
                {
                    this.label.TextColor = this.kDefaultActiveColor;
                }
            };

            var anim2         = CABasicAnimation.FromKeyPath("transform");
            var fromTransform = CATransform3D.MakeScale(1, 1, 1);
            var toTransform   = CATransform3D.MakeScale(0.5f, 0.5f, 1);

            toTransform          = toTransform.Translate(-this.label.Frame.Width / 2, -this.label.Frame.Height, 0);
            anim2.From           = NSValue.FromCATransform3D(fromTransform);
            anim2.To             = NSValue.FromCATransform3D(toTransform);
            anim2.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            var animGroup = new CAAnimationGroup();

            animGroup.Animations          = new CAAnimation[] { anim2 };
            animGroup.Duration            = 0.3;
            animGroup.FillMode            = CAFillMode.Forwards;
            animGroup.RemovedOnCompletion = false;
            this.label.Layer.AddAnimation(animGroup, "_floatingLabel");
            this.ClipsToBounds = false;
            CATransaction.Commit();
        }
コード例 #7
0
        private UICollectionViewLayoutAttributes TransformLayoutAttributes(UICollectionViewLayoutAttributes attributes)
        {
            if (CollectionView == null)
            {
                return(attributes);
            }

            var isHorizontal     = ScrollDirection == UICollectionViewScrollDirection.Horizontal;
            var collectionCenter =
                isHorizontal ? CollectionView.Frame.Size.Width / 2 : CollectionView.Frame.Size.Height / 2;
            var offset           = isHorizontal ? CollectionView.ContentOffset.X : CollectionView.ContentOffset.Y;
            var normalizedCenter = (isHorizontal ? attributes.Center.X : attributes.Center.Y) - offset;

            var maxDistance = (isHorizontal ? ItemSize.Width : ItemSize.Height) + MinimumLineSpacing;
            var distance    = Math.Min(Math.Abs(collectionCenter - normalizedCenter), maxDistance);
            var ratio       = (float)((maxDistance - distance) / maxDistance);

            var alpha = ratio * (1 - SideItemAlpha) + SideItemAlpha;
            var scale = ratio * (1 - SideItemScale) + SideItemScale;
            var shift = (1 - ratio) * SideItemShift;

            attributes.Alpha       = alpha;
            attributes.Transform3D = CATransform3D.MakeScale(scale, scale, 1);
            attributes.ZIndex      = (int)(alpha * 10);

            attributes.Center = isHorizontal
                ? new CGPoint(attributes.Center.X, attributes.Center.Y + shift)
                : new CGPoint(attributes.Center.X + shift, attributes.Center.Y);

            return(attributes);
        }
コード例 #8
0
        /* Dialog close animation then cleaning and removing the view from the parent */
        private void Close()
        {
            var currentTransform   = _dialogView.Layer.Transform;
            var startRotation      = (this.ValueForKeyPath(new NSString("layer.transform.rotation.z")) as NSNumber);
            var startRotationAngle = startRotation.DoubleValue;
            var rotation           = CATransform3D.MakeRotation((nfloat)(-startRotationAngle + Math.PI * 270 / 180d), 0f, 0f, 0f);

            _dialogView.Layer.Transform = rotation.Concat(CATransform3D.MakeScale(1, 1, 1));
            _dialogView.Layer.Opacity   = 1;
            UIView.Animate(0.2, 0d, UIViewAnimationOptions.TransitionNone,
                           () =>
            {
                BackgroundColor             = UIColor.FromRGBA(0, 0, 0, 0);
                _dialogView.Layer.Transform = currentTransform.Concat(CATransform3D.MakeScale(0.6f, 0.6f, 1f));
                _dialogView.Layer.Opacity   = 0;
            },
                           () =>
            {
                var subViews = this.Subviews.ToArray();
                foreach (UIView v in subViews)
                {
                    v.RemoveFromSuperview();
                }
            });
            this.RemoveFromSuperview();
        }
コード例 #9
0
        private void CreateCircleShape(CGRect imageFrame, CGPoint imgCenterPoint)
        {
            _circleShape = new CAShapeLayer()
            {
                Bounds    = imageFrame,
                Position  = imgCenterPoint,
                Path      = UIBezierPath.FromOval(imageFrame).CGPath,
                FillColor = _circleColor.CGColor,
                Transform = CATransform3D.MakeScale(0.0F, 0.0F, 1.0F)
            };

            this.Layer.AddSublayer(_circleShape);

            _circleMask = new CAShapeLayer()
            {
                Bounds   = imageFrame,
                Position = imgCenterPoint,
                FillRule = CAShapeLayer.FillRuleEvenOdd
            };

            _circleShape.Mask = _circleMask;

            var maskPath = UIBezierPath.FromRect(imageFrame);

            maskPath.AddArc(imgCenterPoint, 0.1F, 0.0F, (System.nfloat)(Math.PI * 2F), true);
            _circleMask.Path = maskPath.CGPath;
        }
コード例 #10
0
        void animateLabelBack()
        {
            CATransaction.Begin();
            CATransaction.CompletionBlock = () => {
                this.label.TextColor = this.kDefaultInactiveColor;
            };

            var anim2         = CABasicAnimation.FromKeyPath("transform");
            var fromTransform = CATransform3D.MakeScale(0.5f, 0.5f, 1);

            fromTransform = fromTransform.Translate(-this.label.Frame.Width / 2, -this.label.Frame.Height, 0);
            var toTransform = CATransform3D.MakeScale(1, 1, 1);

            anim2.From           = NSValue.FromCATransform3D(fromTransform);
            anim2.To             = NSValue.FromCATransform3D(toTransform);
            anim2.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            var animGroup = new CAAnimationGroup();

            animGroup.Animations = new CAAnimation[] {
                anim2
            };
            animGroup.Duration            = 0.3;
            animGroup.FillMode            = CAFillMode.Forwards;
            animGroup.RemovedOnCompletion = false;

            this.label.Layer.AddAnimation(animGroup, "_animateLabelBack");
            CATransaction.Commit();
        }
コード例 #11
0
        protected void FloatLabelBack()
        {
            CATransaction.Begin();
            CATransaction.CompletionBlock = () =>
            {
                Label.TextColor = LabelInactiveTextColor;
            };

            var animation     = CABasicAnimation.FromKeyPath("transform");
            var fromTransform = CATransform3D.MakeScale(.5f, .5f, 1);
            var toTransform   = CATransform3D.MakeScale(1, 1, 1);

            fromTransform = fromTransform.Translate(-Label.Frame.Width * 0.5f, -Label.Frame.Height, 0);

            animation.From           = NSValue.FromCATransform3D(fromTransform);
            animation.To             = NSValue.FromCATransform3D(toTransform);
            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);

            var animationGroup = new CAAnimationGroup
            {
                Animations = new CAAnimation[]
                {
                    animation
                },
                Duration            = .3f,
                FillMode            = CAFillMode.Forwards,
                RemovedOnCompletion = false
            };

            Label.Layer.AddAnimation(animationGroup, "_floatLabelBack");

            ClipsToBounds = false;

            CATransaction.Commit();
        }
コード例 #12
0
        private UIViewController ChangeRootViewController(UIViewController viewController)
        {
            if (Window.RootViewController == null)
            {
                Window.RootViewController = viewController;
                return(null);
            }

            var oldRootController = Window.RootViewController;

            var snapShot = Window.SnapshotView(true);

            viewController.View.AddSubview(snapShot);

            Window.RootViewController = viewController;

            UIView.Animate(0.5, () =>
            {
                snapShot.Layer.Opacity   = 0;
                snapShot.Layer.Transform = CATransform3D.MakeScale(1.5f, 1.5f, 1.5f);
            },
                           () =>
            {
                snapShot.RemoveFromSuperview();
            });

            return(oldRootController);
        }
コード例 #13
0
        public void NavigateToUnsafe(Page page, object parameter)
        {
            System.Diagnostics.Debug.WriteLine($"Navigate to  {page.ToString()} in thread {Thread.CurrentThread.ManagedThreadId.ToString()}");

            lock (pagesByKey)
            {
                Type type;
                if (pagesByKey.ContainsKey(page))
                {
                    type = pagesByKey[page].Type;
                }
                else
                {
                    throw new InvalidOperationException($"Unable to navigate: page {page.ToString()} not found");
                }

                if (!CrossConnectivity.Current.IsConnected)
                {
                    var dialogService = ServiceLocator.Current.GetInstance <IDialogService>();
                    dialogService.ShowMessage(LocalizedStrings.ConnectionError, LocalizedStrings.Error);
                    return;
                }

                if (pagesByKey[page].RequireAuth)
                {
                    var accountManager = ServiceLocator.Current.GetInstance <IAccountManager>();
                    if (!accountManager.IsAuthorized())
                    {
                        NavigateTo(Page.SignInPage);
                        return;
                    }
                }

                UIViewController uIViewController;

                uIViewController = CreateController(page, parameter);

                if (pagesByKey[page].IsRoot)
                {
                    UIView snapShot = AppDelegate.Instance.Window.SnapshotView(false);
                    AppDelegate.Instance.Window.RootViewController = new TransparentNavigationController(uIViewController);

                    if (snapShot != null)
                    {
                        uIViewController.View.AddSubview(snapShot);

                        UIView.AnimateNotify(0.3f, () =>
                        {
                            snapShot.Layer.Opacity   = 0;
                            snapShot.Layer.Transform = CATransform3D.MakeScale(1.5f, 1.5f, 1.5f);
                        }, (finished) => snapShot.RemoveFromSuperview());
                    }
                }
                else if (NavigationController.TopViewController == null || !NavigationController.Contains(uIViewController))
                {
                    this.NavigationController.PushViewController(uIViewController, true);
                }
            }
        }
コード例 #14
0
 public void applyPinchToLayoutAttributes(UICollectionViewLayoutAttributes layoutAttributes)
 {
     if (layoutAttributes.IndexPath.Equals(pinchedCellPath))
     {
         layoutAttributes.Transform3D = CATransform3D.MakeScale(pinchedCellScale, pinchedCellScale, 1.0f);
         layoutAttributes.Center      = pinchedCellCenter;
         layoutAttributes.ZIndex      = 1;
     }
 }
コード例 #15
0
        // return layout attributes for a a specific item
        public override UICollectionViewLayoutAttributes LayoutAttributesForItem(NSIndexPath path)
        {
            UICollectionViewLayoutAttributes attributes = UICollectionViewLayoutAttributes.CreateForCell(path);

            attributes.Size   = ItemSize;
            attributes.Center = new PointF(center.X + radius * (float)Math.Cos(2 * path.Row * Math.PI / count),
                                           center.Y + radius * (float)Math.Sin(2 * path.Row * Math.PI / count));
            attributes.Transform3D = CATransform3D.MakeScale(0.5f, 0.5f, 1.0f);
            return(attributes);
        }
コード例 #16
0
        public override UICollectionViewLayoutAttributes FinalLayoutAttributesForDeletedItem(NSIndexPath itemIndexPath)
        {
            var attributes = LayoutAttributesForItem(itemIndexPath);

            attributes.Alpha       = 0;
            attributes.Center      = new PointF(center.X, center.Y);
            attributes.Transform3D = CATransform3D.MakeScale(0.1f, 0.1f, 1);

            return(attributes);
        }
コード例 #17
0
        public async Task ScaleInitializeCorrectly(float scale)
        {
            var view = new TStub()
            {
                Scale = scale,
            };

            var transform = await GetLayerTransformAsync(view);

            var expected = CATransform3D.MakeScale(scale, scale, scale);

            expected.AssertEqual(transform);
        }
コード例 #18
0
        public void BounceTimeLabel()
        {
            // Create key frame animations
            CAKeyFrameAnimation bounce = CAKeyFrameAnimation.GetFromKeyPath("transform");
            CAKeyFrameAnimation fade   = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            // Set the event handler for when the animations stop
            bounce.AnimationStopped += AnimationStopped;
            fade.AnimationStopped   += AnimationStopped;

            // Create the values the bounce animation will pass through
            CATransform3D forward  = CATransform3D.MakeScale(1.3f, 1.3f, 1.0f);
            CATransform3D back     = CATransform3D.MakeScale(0.7f, 0.7f, 1.0f);
            CATransform3D forward2 = CATransform3D.MakeScale(1.2f, 1.2f, 1.0f);
            CATransform3D back2    = CATransform3D.MakeScale(0.9f, 0.9f, 1.0f);

            // Create the values the opacity animation will use to transition between
            NSNumber opacity0 = NSNumber.FromFloat(0.0f);
            NSNumber opacity1 = NSNumber.FromFloat(1.0f);

            bounce.Values = new NSObject[] {
                // Start from the default values set in the XIB
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(forward),
                NSValue.FromCATransform3D(back),
                NSValue.FromCATransform3D(forward2),
                NSValue.FromCATransform3D(back2),
                // Return to the default values set in the XIB
                NSValue.FromCATransform3D(CATransform3D.Identity)
            };

            fade.Values = new NSObject[] {
                // Get the starting value form the modal layer
                NSNumber.FromFloat(lblTime.Layer.Opacity),
                opacity1,
                opacity0,
                opacity1,
                opacity0,
                // Get the ending value from the modal layer
                NSNumber.FromFloat(lblTime.Layer.Opacity)
            };

            // Set the animation duration
            bounce.Duration = 5.0f;
            fade.Duration   = 5.0f;

            // Animate the CALayer of the time label (lblTime)
            lblTime.Layer.AddAnimation(bounce, "bounceAnimation");
            lblTime.Layer.AddAnimation(fade, "fadeAnimation");
        }
コード例 #19
0
        void animationZoom(int i, float offset)
        {
            var transform = CATransform3D.Identity;
            var tmpOffset = offset;

            if (tmpOffset > 1.0)
            {
                tmpOffset = (float)(1.0 + (1.0 - tmpOffset));
            }
            var scale = (float)(1.0 - tmpOffset);

            //TODO: Check --> CATransform3DScale(transform, 1 - scale, 1 - scale, 1.0);
            transform = CATransform3D.MakeScale(1 - scale, 1 - scale, (System.nfloat) 1.0);
            applyTransform(i, transform);
        }
コード例 #20
0
        private void CreateCircleTransformAnimation(CGRect imageFrame)
        {
            _circleTransform.Duration = 0.333;                                          // 0.0333 * 10
            _circleTransform.Values   = new NSObject[8] {
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.0F, 0.0F, 1.0F)),   //  0/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(0.5F, 0.5F, 1.0F)),   //  1/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.0F, 1.0F, 1.0F)),   //  2/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.2F, 1.0F, 1.0F)),   //  3/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.3F, 1.3F, 1.0F)),   //  4/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.37F, 1.37F, 1.0F)), //  5/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.4F, 1.4F, 1.0F)),   //  6/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(1.4F, 1.4F, 1.0F))    // 10/10
            };
            _circleTransform.KeyTimes = new NSNumber[8] {
                NSNumber.FromDouble(0.0),        //  0/10
                NSNumber.FromDouble(0.1),        //  1/10
                NSNumber.FromDouble(0.2),        //  2/10
                NSNumber.FromDouble(0.3),        //  3/10
                NSNumber.FromDouble(0.4),        //  4/10
                NSNumber.FromDouble(0.5),        //  5/10
                NSNumber.FromDouble(0.6),        //  6/10
                NSNumber.FromDouble(1.0)         // 10/10
            };

            _circleMaskTransform.Duration = 0.333;                                                                               // 0.0333 * 10
            _circleMaskTransform.Values   = new NSObject[9] {
                NSValue.FromCATransform3D(CATransform3D.Identity),                                                               //  0/10
                NSValue.FromCATransform3D(CATransform3D.Identity),                                                               //  2/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 1.25F, imageFrame.Height * 1.25F, 1.0F)),   //  3/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 2.688F, imageFrame.Height * 2.688F, 1.0F)), //  4/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 3.923F, imageFrame.Height * 3.923F, 1.0F)), //  5/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 4.375F, imageFrame.Height * 4.375F, 1.0F)), //  6/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 4.731F, imageFrame.Height * 4.731F, 1.0F)), //  7/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 5.0F, imageFrame.Height * 5.0F, 1.0F)),     //  9/10
                NSValue.FromCATransform3D(CATransform3D.MakeScale(imageFrame.Width * 5.0F, imageFrame.Height * 5.0F, 1.0F))      // 10/10
            };
            _circleMaskTransform.KeyTimes = new NSNumber[9] {
                NSNumber.FromDouble(0.0),        //  0/10
                NSNumber.FromDouble(0.2),        //  2/10
                NSNumber.FromDouble(0.3),        //  3/10
                NSNumber.FromDouble(0.4),        //  4/10
                NSNumber.FromDouble(0.5),        //  5/10
                NSNumber.FromDouble(0.6),        //  6/10
                NSNumber.FromDouble(0.7),        //  7/10
                NSNumber.FromDouble(0.9),        //  9/10
                NSNumber.FromDouble(1.0)         // 10/10
            };
        }
コード例 #21
0
        public void Show(string title, string doneButtonTitle, string cancelButtonTitle, UIDatePickerMode datePickerMode, Action <DateTime> callback, DateTime defaultDate, DateTime?maximumDate = null, DateTime?minimumDate = null, Action cancelCallback = null)
        {
            if (_isDialogShown)
            {
                return;            // if already dialog is shown, do not open another dialog
            }
            _isDialogShown = true; // update the flag

            _title             = title;
            _doneButtonTitle   = doneButtonTitle;
            _cancelButtonTitle = cancelButtonTitle;
            _datePickerMode    = datePickerMode;
            _callback          = callback;
            _defaultDate       = defaultDate;
            _maximumDate       = maximumDate;
            _minimumDate       = minimumDate;
            _cancelCallback    = cancelCallback;

            _dialogView = createContainerView();

            _dialogView.Layer.ShouldRasterize    = true;
            _dialogView.Layer.RasterizationScale = UIScreen.MainScreen.Scale;

            Layer.ShouldRasterize    = true;
            Layer.RasterizationScale = UIScreen.MainScreen.Scale;

            _dialogView.Layer.Opacity   = 0.5f;
            _dialogView.Layer.Transform = CATransform3D.MakeScale(1.3f, 1.3f, 1);

            BackgroundColor = UIColor.FromRGBA(0, 0, 0, 0);

            AddSubview(_dialogView);

            var widthHeight = Frame.Width > Frame.Height ? Frame.Width : Frame.Height; // check if width is greator than width, return whever is greator

            Frame = new CGRect(0, 0, widthHeight, widthHeight);                        // create overlay with max value from height and width so that on rotaion whole screen is covered

            UIApplication.SharedApplication.Windows[0].AddSubview(this);

            UIView.Animate(0.2, 0d, UIViewAnimationOptions.CurveEaseInOut, () =>
            {
                BackgroundColor             = UIColor.Black.ColorWithAlpha(0.4f);
                _dialogView.Layer.Opacity   = 1;
                _dialogView.Layer.Transform = CATransform3D.MakeScale(1, 1, 1);
            }, () =>
            {
            });
        }
コード例 #22
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            var size  = (nfloat)Math.Min(Frame.Width, Frame.Height);
            var scale = size / pathSize;

            foreach (var layer in new[] { circle, check, shape })
            {
                if (layer != null)
                {
                    layer.Position  = new CGPoint(Frame.Width / 2f, Frame.Height / 2f);
                    layer.Transform = CATransform3D.MakeScale(scale, scale, 1);
                }
            }
        }
コード例 #23
0
        /* Animation engine to create a fill animation.
         * @param bounces The number of bounces for the animation.
         * @param amplitue How far does the animation bounce.
         * @param reserve Flag to track if the animation should fill or empty the layer.
         * @return Returns the CAKeyframeAnimation object.
         */
        public CAKeyFrameAnimation FillAnimationWithBounces(int bounces, float amplitude, bool reverse)
        {
            List <NSObject> values   = new List <NSObject>();
            List <NSNumber> keyTimes = new List <NSNumber>();

            if (reverse)
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(1, 1, 1)));
            }
            else
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(0, 0, 0)));
            }


            keyTimes.Add(new NSNumber(0));

            for (int i = 1; i <= bounces; i++)
            {
                var scale = (i % 2) > 0 ? (1 + amplitude / i) : (1 - amplitude / i);
                var time  = (float)(i * (1.0 / (bounces + 1)));
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(scale, scale, scale)));
                keyTimes.Add(new NSNumber(time));
            }

            if (reverse)
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(new nfloat(0.0001), new nfloat(0.0001), new nfloat(0.0001))));
            }
            else
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(1, 1, 1)));
            }

            keyTimes.Add(new NSNumber(1));

            CAKeyFrameAnimation animation = CAKeyFrameAnimation.FromKeyPath("transform");

            animation.Values              = values.ToArray();
            animation.KeyTimes            = keyTimes.ToArray();
            animation.RemovedOnCompletion = false;
            animation.FillMode            = CAFillMode.Forwards;
            animation.Duration            = AnimationDuration;
            animation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

            return(animation);
        }
コード例 #24
0
ファイル: PickerDialog.cs プロジェクト: punker76/Diabetto
        /* Dialog close animation then cleaning and removing the view from the parent */
        private void Close()
        {
            var currentTransform = _dialogView.Layer.Transform;

            if (ValueForKeyPath(new NSString(str: "layer.transform.rotation.z")) is NSNumber startRotation)
            {
                var startRotationAngle = startRotation.DoubleValue;

                var rotation = CATransform3D.MakeRotation(
                    (nfloat)(-startRotationAngle + Math.PI * 270 / 180d),
                    x: 0f,
                    y: 0f,
                    z: 0f);

                _dialogView.Layer.Transform = rotation.Concat(CATransform3D.MakeScale(sx: 1, sy: 1, sz: 1));
            }

            _dialogView.Layer.Opacity = 1;

            Animate(
                duration: 0.2,
                delay: 0d,
                UIViewAnimationOptions.TransitionNone,
                animation: () =>
            {
                BackgroundColor = UIColor.FromRGBA(
                    red: 0,
                    green: 0,
                    blue: 0,
                    alpha: 0);

                _dialogView.Layer.Transform = currentTransform.Concat(CATransform3D.MakeScale(sx: 0.6f, sy: 0.6f, sz: 1f));
                _dialogView.Layer.Opacity   = 0;
            },
                completion: () =>
            {
                var subViews = Subviews.ToArray();

                foreach (var v in subViews)
                {
                    v.RemoveFromSuperview();
                }
            });

            RemoveFromSuperview();
        }
コード例 #25
0
        void showInactiveBorder()
        {
            CATransaction.Begin();
            CATransaction.CompletionBlock = () => {
                this.activeBorder.Layer.Opacity = 0;
            };
            var anim2         = CABasicAnimation.FromKeyPath("transform");
            var fromTransform = CATransform3D.MakeScale(1, 1, 1);
            var toTransform   = CATransform3D.MakeScale(0.01f, 1, 1);

            anim2.From                = NSValue.FromCATransform3D(fromTransform);
            anim2.To                  = NSValue.FromCATransform3D(toTransform);
            anim2.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            anim2.FillMode            = CAFillMode.Forwards;
            anim2.RemovedOnCompletion = false;
            this.activeBorder.Layer.AddAnimation(anim2, "_activeBorder");
            CATransaction.Commit();
        }
コード例 #26
0
        public void BounceTimeLabel()
        {
            // Create a key frame animation
            CAKeyFrameAnimation bounce = CAKeyFrameAnimation.GetFromKeyPath("transform");
            CAKeyFrameAnimation fade   = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            bounce.AnimationStopped += AnimationStopped;
            fade.AnimationStopped   += AnimationStopped;

            // Create the values it will pass through
            CATransform3D forward  = CATransform3D.MakeScale(1.3f, 1.3f, 1.0f);
            CATransform3D back     = CATransform3D.MakeScale(0.7f, 0.7f, 1.0f);
            CATransform3D forward2 = CATransform3D.MakeScale(1.2f, 1.2f, 1.0f);
            CATransform3D back2    = CATransform3D.MakeScale(0.9f, 0.9f, 1.0f);

            NSNumber opacity0 = NSNumber.FromFloat(0.0f);
            NSNumber opacity1 = NSNumber.FromFloat(1.0f);

            bounce.Values = new NSObject[] {
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(forward),
                NSValue.FromCATransform3D(back),
                NSValue.FromCATransform3D(forward2),
                NSValue.FromCATransform3D(back2),
                NSValue.FromCATransform3D(CATransform3D.Identity)
            };

            fade.Values = new NSObject[] {
                NSNumber.FromFloat(lblTime.Layer.Opacity),
                opacity1,
                opacity0,
                opacity1,
                opacity0,
                NSNumber.FromFloat(lblTime.Layer.Opacity)
            };

            // Set the duration
            bounce.Duration = 5.0f;
            fade.Duration   = 5.0f;

            // Animate the layer
            lblTime.Layer.AddAnimation(bounce, "bounceAnimation");
            lblTime.Layer.AddAnimation(fade, "fadeAnimation");
        }
コード例 #27
0
 private void CreateImageTransformAnimation()
 {
     _imageTransform.Duration = 1.0;                                               //0.0333 * 30
     _imageTransform.Values   = new NSObject[17] {
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.0F, 0.0F, 1.0F)),     //  0/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.0F, 0.0F, 1.0F)),     //  3/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(1.2F, 1.2F, 1.0F)),     //  9/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(1.25F, 1.25F, 1.0F)),   // 10/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(1.2F, 1.2F, 1.0F)),     // 11/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.9F, 0.9F, 1.0F)),     // 14/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.875F, 0.875F, 1.0F)), // 15/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.875F, 0.875F, 1.0F)), // 16/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.9F, 0.9F, 1.0F)),     // 17/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(1.013F, 1.013F, 1.0F)), // 20/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(1.025F, 1.025F, 1.0F)), // 21/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(1.013F, 1.013F, 1.0F)), // 22/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.96F, 0.96F, 1.0F)),   // 25/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.95F, 0.95F, 1.0F)),   // 26/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.96F, 0.96F, 1.0F)),   // 27/30
         NSValue.FromCATransform3D(CATransform3D.MakeScale(0.99F, 0.99F, 1.0F)),   // 29/30
         NSValue.FromCATransform3D(CATransform3D.Identity)                         // 30/30
     };
     _imageTransform.KeyTimes = new NSNumber[17] {
         NSNumber.FromDouble(0.0),        //  0/30
         NSNumber.FromDouble(0.1),        //  3/30
         NSNumber.FromDouble(0.3),        //  9/30
         NSNumber.FromDouble(0.333),      // 10/30
         NSNumber.FromDouble(0.367),      // 11/30
         NSNumber.FromDouble(0.467),      // 14/30
         NSNumber.FromDouble(0.5),        // 15/30
         NSNumber.FromDouble(0.533),      // 16/30
         NSNumber.FromDouble(0.567),      // 17/30
         NSNumber.FromDouble(0.667),      // 20/30
         NSNumber.FromDouble(0.7),        // 21/30
         NSNumber.FromDouble(0.733),      // 22/30
         NSNumber.FromDouble(0.833),      // 25/30
         NSNumber.FromDouble(0.867),      // 26/30
         NSNumber.FromDouble(0.9),        // 27/30
         NSNumber.FromDouble(0.967),      // 29/30
         NSNumber.FromDouble(1.0)         // 30/30
     };
 }
コード例 #28
0
ファイル: ViewExtensions.cs プロジェクト: nagyist/iOSHelpers
        public static UIView Pulse(this UIView view, float max)
        {
            var transformAnimation = CAKeyFrameAnimation.GetFromKeyPath("transform");

            transformAnimation.CalculationMode = CAAnimation.AnimationPaced;
            transformAnimation.FillMode        = CAFillMode.Forwards;
            transformAnimation.TimingFunction  = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            //			pathAnimation.RemovedOnCompletion = false;
            transformAnimation.Duration = .2;

            var transform = CATransform3D.MakeScale(max, max, 1);

            transformAnimation.Values = new [] {
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(transform),
                NSValue.FromCATransform3D(CATransform3D.Identity),
            };
            view.Layer.AddAnimation(transformAnimation, "pulse");
            return(view);
        }
コード例 #29
0
        public void UpdateItemsCount(int count)
        {
            ItemsCount = count;
            var pathAnimation = CAKeyFrameAnimation.GetFromKeyPath("transform");

            pathAnimation.CalculationMode = CAAnimation.AnimationPaced;
            pathAnimation.FillMode        = CAFillMode.Forwards;
            pathAnimation.TimingFunction  = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
//			pathAnimation.RemovedOnCompletion = false;
            pathAnimation.Duration = .2;

            var transform = CATransform3D.MakeScale(2f, 2f, 1);

            pathAnimation.Values = new [] {
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(transform),
                NSValue.FromCATransform3D(CATransform3D.Identity),
            };
            badge.Layer.AddAnimation(pathAnimation, "pulse");
        }
コード例 #30
0
        public override UICollectionViewLayoutAttributes[] LayoutAttributesForElementsInRect(RectangleF rect)
        {
            var array       = base.LayoutAttributesForElementsInRect(rect);
            var visibleRect = new RectangleF(CollectionView.ContentOffset, CollectionView.Bounds.Size);

            foreach (var attributes in array)
            {
                if (attributes.Frame.IntersectsWith(rect))
                {
                    float distance           = visibleRect.GetMidX() - attributes.Center.X;
                    float normalizedDistance = distance / ACTIVE_DISTANCE;
                    if (Math.Abs(distance) < ACTIVE_DISTANCE)
                    {
                        float zoom = 1 + ZOOM_FACTOR * (1 - Math.Abs(normalizedDistance));
                        attributes.Transform3D = CATransform3D.MakeScale(zoom, zoom, 1.0f);
                        attributes.ZIndex      = 1;
                    }
                }
            }
            return(array);
        }