void HidePanel() { entryField.ResignFirstResponder(); CATransition transition = CATransition.CreateAnimation(); transition.Duration = kAnimationDuration; transition.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); transition.Type = CATransition.TransitionPush.ToString(); transition.Subtype = CATransition.TransitionFromTop.ToString(); Layer.AddAnimation(transition, null); Frame = new RectangleF(0, (float)-Frame.Height, 320, (float)Frame.Height); transition = CATransition.CreateAnimation(); transition.Duration = kAnimationDuration; transition.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); transition.Type = CATransition.TransitionFade.ToString(); dimView.Alpha = 0; dimView.Layer.AddAnimation(transition, null); NSTimer.CreateScheduledTimer(0.40, #if __UNIFIED__ timer #else () #endif => { dimView.RemoveFromSuperview(); }
void OnElementPropertyChanging(object sender, PropertyChangingEventArgs e) { if (e.PropertyName == Image.SourceProperty.PropertyName) { var transition = new CATransition { TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut), Duration = ((double)ImageSwitcher.TransitionDuration) / 1000 }; switch (ImageSwitcher.TransitionType) { case TransitionType.Fade: transition.Type = CAAnimation.TransitionFade; break; case TransitionType.MoveInFromLeft: transition.Type = CAAnimation.TransitionMoveIn; transition.Subtype = CAAnimation.TransitionFromLeft; break; } Layer.AddAnimation(transition, transition.Type); } }
public PulseAnimationView() { _animationGroup = CreateAnimation(); Layer.AddAnimation(_animationGroup, "pulse"); NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, AnimationWillEnterForeground); NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidEnterBackgroundNotification, AnimationDidEnterBackground); }
/// <summary> /// Starts the spinning animation of the activity indicator. /// NOTE: may not work when called from ViewDidLoad, use ViewWillAppear or ViewDidAppear. /// </summary> public void StartSpinning() { var animation = createAnimation(); Layer.RemoveAllAnimations(); Layer.AddAnimation(animation, "spinning"); }
public void Rotate() { CASpringAnimation rotationAnimation = new CASpringAnimation(); rotationAnimation.KeyPath = "transform.rotation.z"; rotationAnimation.RepeatCount = 1; rotationAnimation.InitialVelocity = 5; rotationAnimation.Mass = 1.5f; rotationAnimation.RemovedOnCompletion = false; rotationAnimation.FillMode = CAFillMode.Forwards; if (upsideDown) { rotationAnimation.From = new NSNumber(Math.PI); rotationAnimation.To = new NSNumber(Math.PI * 2); } else { rotationAnimation.From = new NSNumber(0); rotationAnimation.To = new NSNumber(Math.PI); } rotationAnimation.Duration = rotationAnimation.SettlingDuration; Layer.AddAnimation(rotationAnimation, nameof(rotationAnimation)); upsideDown = !upsideDown; }
private void Expand(Action completion) { var expandAnim = CABasicAnimation.FromKeyPath("transform.scale"); expandAnim.From = NSNumber.FromFloat(1.0f); expandAnim.To = NSNumber.FromFloat(26.0f); expandAnim.TimingFunction = expandCurve; expandAnim.Duration = 0.3; expandAnim.FillMode = CAFillMode.Forwards; expandAnim.RemovedOnCompletion = false; expandAnim.AnimationStopped += delegate { OnAnimationComplete(); if (completion != null) { completion(); } CreateScheduledTimer(1.0, () => { ReturnToOriginalState(); isAnimating = false; }); }; Layer.AddAnimation(expandAnim, expandAnim.KeyPath); }
private void Animate() { var rotationAnimation = CABasicAnimation.FromKeyPath(@"transform.rotation.z"); rotationAnimation.To = FromObject(Math.PI * 2.0); rotationAnimation.Duration = 1; rotationAnimation.AutoReverses = false; rotationAnimation.RepeatCount = 1; rotationAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear); Layer.AddAnimation(rotationAnimation, "rotationAnimation"); }
public override void StopAnimating() { if (_animation != null && Layer.Speed != 0.0f) { Layer.RemoveAnimation(AnimationLayerName); Layer.AddAnimation(_animation, AnimationLayerName); Layer.Speed = 0.0f; } else { base.StopAnimating(); } }
private void Shrink() { var shrinkAnim = CABasicAnimation.FromKeyPath("bounds.size.width"); shrinkAnim.From = NSNumber.FromDouble(Frame.Width); shrinkAnim.To = NSNumber.FromDouble(Frame.Height); shrinkAnim.Duration = shrinkDuration; shrinkAnim.TimingFunction = shrinkCurve; shrinkAnim.FillMode = CAFillMode.Forwards; shrinkAnim.RemovedOnCompletion = false; Layer.AddAnimation(shrinkAnim, shrinkAnim.KeyPath); }
public override bool BeginTracking(UITouch touch, UIEvent uievent) { if (TrackTouchLocation) { _touchCenterLocation = touch.LocationInView(this); } else { _touchCenterLocation = null; } UIView.Animate(0.1, 0, UIViewAnimationOptions.AllowUserInteraction, () => { _rippleBackgroundView.Alpha = 1; }, null); _rippleView.Transform = CGAffineTransform.MakeScale(0.5f, 0.5f); UIView.Animate(0.7, 0, UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction, () => { _rippleView.Transform = CGAffineTransform.MakeIdentity(); }, null); if (ShadowRippleEnable) { _tempShadowRadius = Layer.ShadowRadius; _tempShadowOpacity = Layer.ShadowOpacity; var shadowAnim = new CABasicAnimation { KeyPath = "shadowRadius" }; shadowAnim.To = NSValue.FromObject(ShadowRippleRadius); var opacityAnim = new CABasicAnimation { KeyPath = "shadowOpacity" }; opacityAnim.To = NSValue.FromObject(1); var groupAnim = new CAAnimationGroup(); groupAnim.Duration = 0.7; groupAnim.FillMode = CAFillMode.Forwards; groupAnim.RemovedOnCompletion = false; groupAnim.Animations = new[] { shadowAnim, opacityAnim }; Layer.AddAnimation(groupAnim, "shadow"); } return(base.BeginTracking(touch, uievent)); }
void LiftButton() { if (IsRaised) { nfloat startRadius = LoweredShadowRadius; nfloat startOpacity = LoweredShadowOpacity; CGPath startPath = UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath; if (Layer.AnimationKeys != null && Layer.AnimationKeys.Length > 0) { startRadius = Layer.PresentationLayer.ShadowRadius; startOpacity = Layer.PresentationLayer.ShadowOpacity; startPath = Layer.PresentationLayer.ShadowPath; } CABasicAnimation increaseRadius = CABasicAnimation.FromKeyPath("shadowRadius"); increaseRadius.From = NSNumber.FromNFloat(startRadius); increaseRadius.To = NSNumber.FromNFloat(LiftedShadowRadius); increaseRadius.Duration = TouchDownAnimationDuration; increaseRadius.FillMode = CAFillMode.Forwards; increaseRadius.RemovedOnCompletion = true; Layer.ShadowRadius = LiftedShadowRadius; CABasicAnimation shadowOpacityAnimation = CABasicAnimation.FromKeyPath("shadowOpacity"); shadowOpacityAnimation.Duration = TouchDownAnimationDuration; shadowOpacityAnimation.From = NSNumber.FromNFloat(startOpacity); shadowOpacityAnimation.To = NSNumber.FromNFloat(LiftedShadowOpacity); shadowOpacityAnimation.FillMode = CAFillMode.Backwards; shadowOpacityAnimation.RemovedOnCompletion = true; Layer.ShadowOpacity = LiftedShadowOpacity; CABasicAnimation shadowPathAnimation = CABasicAnimation.FromKeyPath("shadowPath"); shadowPathAnimation.Duration = TouchDownAnimationDuration; shadowPathAnimation.SetFrom(startPath); shadowPathAnimation.SetTo(UIBezierPath.FromRoundedRect(UpRect, CornerRadius).CGPath); shadowPathAnimation.FillMode = CAFillMode.Forwards; shadowPathAnimation.RemovedOnCompletion = true; Layer.ShadowPath = UIBezierPath.FromRoundedRect(UpRect, CornerRadius).CGPath; Layer.AddAnimation(increaseRadius, "shadowRadius"); Layer.AddAnimation(shadowOpacityAnimation, "shadowOpacity"); Layer.AddAnimation(shadowPathAnimation, "shadow"); } }
protected override void Initialization() { Layer layer1 = new Layer(); Letter title = new Letter( "!light", new Font(@"Consolas", 28, FontStyle.Underline | FontStyle.Bold), root.Center() //Position.Center(root) ); //layer1.Add(layer1.bucket(0, 0, Color.White)); layer1.Add( title.AddAnimation(Fade.In(1).AddEasing(Easing.In.Quad)) .AddAnimation( new Flashing(opacityA: 1, opacityB: 0.9, cycle: 0.6, cycleGap: 0.2).LoopReverse(), new Glowing(color: Color.Black, range: 14, cycle: 0.6).LoopReverse() ) ); layer1.AddAnimation(Fade.In(4).AddEasing(Easing.Out.Quad)); layer1.OnClicked += Layer1_OnClicked; Add(layer1); }
void Spin() { if (!IsRotating) { return; } if (Layer.AnimationForKey("Rotation") != null) { return; } var animation = new CABasicAnimation(); animation.KeyPath = "transform.rotation.z"; animation.To = NSNumber.FromDouble(Math.PI * 2); animation.Duration = 2.0; animation.Cumulative = true; animation.RepeatCount = 1; animation.AnimationStopped += (s, a) => Spin(); Layer.AddAnimation(animation, "Rotation"); }
private void AnimateToNormal() { UIView.Animate(0.1, 0, UIViewAnimationOptions.AllowUserInteraction, () => { _rippleBackgroundView.Alpha = 1; }, () => { UIView.Animate(TouchUpAnimationTime, 0, UIViewAnimationOptions.AllowUserInteraction, () => { _rippleBackgroundView.Alpha = 0; }, null); }); UIView.Animate(0.7, 0, UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.BeginFromCurrentState | UIViewAnimationOptions.AllowUserInteraction, () => { _rippleView.Transform = CGAffineTransform.MakeIdentity(); var shadowAnim = new CABasicAnimation { KeyPath = "shadowRadius" }; shadowAnim.To = NSObject.FromObject(_tempShadowRadius); var opacityAnim = new CABasicAnimation { KeyPath = "shadowOpacity" }; opacityAnim.To = NSObject.FromObject(_tempShadowOpacity); var groupAnim = new CAAnimationGroup(); groupAnim.Duration = 0.7; groupAnim.FillMode = CAFillMode.Forwards; groupAnim.RemovedOnCompletion = false; groupAnim.Animations = new[] { shadowAnim, opacityAnim }; Layer.AddAnimation(groupAnim, "shadowBack"); }, null); }
private void AnimationWillEnterForeground(NSNotification notification) { Layer.AddAnimation(_animationGroup, "pulse"); }
public void RestartAnimation() { Layer.RemoveAnimation("pulse"); Layer.AddAnimation(_animationGroup, "pulse"); }
void nextImage(NSTimer timer) { if (Images.Count == 0 || currentIndex >= Images.Count && !ShouldLoop) { if (Finished != null) { Finished(this, EventArgs.Empty); } return; } if (currentIndex >= Images.Count) { currentIndex = 0; } UIImage image = Images[currentIndex]; currentIndex++; if (image == null) { if (image == null || image.Size == Size.Empty) { return; } } nfloat resizeRatio = -1; nfloat widthDiff = -1; nfloat heightDiff = -1; nfloat originX = -1; nfloat originY = -1; nfloat zoomInX = -1; nfloat zoomInY = -1; nfloat moveX = -1; nfloat moveY = -1; nfloat frameWidth = IsLandscape ? Bounds.Width : Bounds.Height; nfloat frameHeight = IsLandscape ? Bounds.Height : Bounds.Width; // Wider than screen nfloat imageWidth = image.Size.Width == 0 ? 100 : image.Size.Width; nfloat imageHeight = image.Size.Height == 0 ? 100 : image.Size.Height; if (imageWidth > frameWidth) { widthDiff = imageWidth - frameWidth; // Higher than screen if (imageHeight > frameHeight) { heightDiff = imageHeight - frameHeight; if (widthDiff > heightDiff) { resizeRatio = frameHeight / imageHeight; } else { resizeRatio = frameWidth / imageWidth; } // No higher than screen [OK] } else { heightDiff = frameHeight - imageHeight; if (widthDiff > heightDiff) { resizeRatio = frameWidth / imageWidth; } else { resizeRatio = Bounds.Height / imageHeight; } } // No wider than screen } else { widthDiff = frameWidth - imageWidth; // Higher than screen [OK] if (imageHeight > frameHeight) { heightDiff = imageHeight - frameHeight; if (widthDiff > heightDiff) { resizeRatio = imageHeight / frameHeight; } else { resizeRatio = frameWidth / imageWidth; } // No higher than screen [OK] } else { heightDiff = frameHeight - imageHeight; if (widthDiff > heightDiff) { resizeRatio = frameWidth / imageWidth; } else { resizeRatio = frameHeight / imageHeight; } } } // Resize the image. var optimusWidth = (imageWidth * resizeRatio) * enlargeRatio; var optimusHeight = (imageHeight * resizeRatio) * enlargeRatio; var imageView = new UIView { Frame = new CGRect(0, 0, optimusWidth, optimusHeight), BackgroundColor = UIColor.Clear, }; var maxMoveX = (nfloat)Math.Min(optimusWidth - frameWidth, 50f); var maxMoveY = (nfloat)Math.Min(optimusHeight - frameHeight, 50f) * 2 / 3; float rotation = (random.Next(9)) / 100; switch (random.Next(3)) { case 0: originX = 0; originY = 0; zoomInX = 1.25f; zoomInY = 1.25f; moveX = -maxMoveX; moveY = -maxMoveY; break; case 1: originX = 0; originY = 0; // Math.Max(frameHeight - (optimusHeight),frameHeight * 1/3); zoomInX = 1.1f; zoomInY = 1.1f; moveX = -maxMoveX; moveY = maxMoveY; break; case 2: originX = frameWidth - optimusWidth; originY = 0; zoomInX = 1.3f; zoomInY = 1.3f; moveX = maxMoveX; moveY = -maxMoveY; break; default: originX = frameWidth - optimusWidth; originY = 0; //Math.Max(frameHeight - (optimusHeight),frameHeight * 1/3); zoomInX = 1.2f; zoomInY = 1.2f; moveX = maxMoveX; moveY = maxMoveY; break; } var picLayer = new CALayer { Contents = image.CGImage, AnchorPoint = PointF.Empty, Bounds = imageView.Bounds, Position = new CGPoint(originX, originY) }; imageView.Layer.AddSublayer(picLayer); var animation = new CATransition { Duration = 1, Type = CAAnimation.TransitionFade, }; Layer.AddAnimation(animation, null); Views.Enqueue(imageView); while (Views.Count > imageBuffer) { Views.Dequeue().RemoveFromSuperview(); } AddSubview(imageView); Animate(ImageDuration + 2, 0, UIViewAnimationOptions.CurveEaseIn, () => { CGAffineTransform t = CGAffineTransform.MakeRotation(rotation); t.Translate(moveX, moveY); t.Scale(zoomInX, zoomInY); imageView.Transform = t; }, null); if (ImageIndexChanged != null) { ImageIndexChanged(currentIndex); } }
void LowerButtonAndFadeOutBackground() { if (IsRaised) { nfloat startRadius = LiftedShadowRadius; nfloat startOpacity = LiftedShadowOpacity; CGPath startPath = UIBezierPath.FromRoundedRect(UpRect, CornerRadius).CGPath; if (Layer.AnimationKeys != null && Layer.AnimationKeys.Length > 0) { startRadius = Layer.PresentationLayer.ShadowRadius; startOpacity = Layer.PresentationLayer.ShadowOpacity; startPath = Layer.PresentationLayer.ShadowPath; } CABasicAnimation decreaseRadius = CABasicAnimation.FromKeyPath("shadowRadius"); decreaseRadius.SetFrom(NSNumber.FromNFloat(startRadius)); decreaseRadius.SetTo(NSNumber.FromNFloat(LoweredShadowRadius)); decreaseRadius.Duration = TouchUpAnimationDuration; decreaseRadius.FillMode = CAFillMode.Forwards; decreaseRadius.RemovedOnCompletion = true; Layer.ShadowRadius = LoweredShadowRadius; CABasicAnimation shadowOpacityAnimation = CABasicAnimation.FromKeyPath("shadowOpacity"); shadowOpacityAnimation.Duration = TouchUpAnimationDuration; shadowOpacityAnimation.SetFrom(NSNumber.FromNFloat(startOpacity)); shadowOpacityAnimation.SetTo(NSNumber.FromNFloat(LoweredShadowOpacity)); shadowOpacityAnimation.FillMode = CAFillMode.Backwards; shadowOpacityAnimation.RemovedOnCompletion = true; Layer.ShadowOpacity = LoweredShadowOpacity; CABasicAnimation shadowAnimation = CABasicAnimation.FromKeyPath("shadowPath"); shadowAnimation.Duration = TouchUpAnimationDuration; shadowAnimation.SetFrom(startPath); shadowAnimation.SetTo(UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath); shadowAnimation.FillMode = CAFillMode.Forwards; shadowAnimation.RemovedOnCompletion = true; Layer.ShadowPath = UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath; Layer.AddAnimation(shadowAnimation, "shadow"); Layer.AddAnimation(decreaseRadius, "shadowRadius"); Layer.AddAnimation(shadowOpacityAnimation, "shadowOpacity"); } if (IsColorClear(BackgroundColor)) { nfloat startingOpacity = BackgroundColorFadeLayer.Opacity; if (BackgroundColorFadeLayer.AnimationKeys != null && BackgroundColorFadeLayer.AnimationKeys.Length > 0 && BackgroundColorFadeLayer.PresentationLayer != null) { startingOpacity = BackgroundColorFadeLayer.PresentationLayer.Opacity; } CABasicAnimation removeFadeBackgroundDarker = CABasicAnimation.FromKeyPath("opacity"); removeFadeBackgroundDarker.Duration = TouchUpAnimationDuration; removeFadeBackgroundDarker.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear); removeFadeBackgroundDarker.SetFrom(NSNumber.FromNFloat(startingOpacity)); removeFadeBackgroundDarker.SetTo(NSNumber.FromNFloat(0)); removeFadeBackgroundDarker.FillMode = CAFillMode.Forwards; removeFadeBackgroundDarker.RemovedOnCompletion = !false; BackgroundColorFadeLayer.Opacity = 0; BackgroundColorFadeLayer.AddAnimation(removeFadeBackgroundDarker, "animateOpacity"); } }