void Panned(NSObject r) { var recognizer = r as UIPanGestureRecognizer; var touchPoint = recognizer.LocationInView(View); switch (recognizer.State) { case UIGestureRecognizerState.Began: originalTouchPoint = touchPoint; break; case UIGestureRecognizerState.Changed: var offset = touchPoint.Y - originalTouchPoint.Y; offset = offset > 0 ? NMath.Pow(offset, 0.7f) : -NMath.Pow(-offset, 0.7f); rubberView.Transform = CGAffineTransform.MakeTranslation(0, offset); break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.6f, response: .3f); var animator = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters); animator.AddAnimations(() => rubberView.Transform = CGAffineTransform.MakeIdentity()); animator.Interruptible = true; animator.StartAnimation(); break; default: break; } }
private void PerformFlyover(Flyover flyover) { if (!flyover.Coordinate.IsValid()) { return; } if (_mapView == null) { return; } // Increase heading by heading step for _mapCamera _mapCamera.Heading += Configuration.HeadingStep; _mapCamera.Heading = _mapCamera.Heading % 360; // Initialize UIViewPropertyAnimator _animator = new UIViewPropertyAnimator( Configuration.Duration, Curve, animations: () => { _mapView.Camera = _mapCamera; }); // Add completion _animator?.SetCompletion((a) => { if (_flyover.NearlyEquals(flyover)) { PerformFlyover(flyover); } }); // Start animation _animator?.StartAnimation(); }
void AnimateMenu(MenuState newMenuState, float initialVelocity = 0.7f) { var initialVelocityVector = new CGVector(initialVelocity, 0f); var springParameters = GetSpringTimingParameters(initialVelocityVector); var shouldMaximize = newMenuState == MenuState.Open; menuAnimator = new UIViewPropertyAnimator(0, springParameters) { Interruptible = true, }; menuAnimator.AddAnimations(() => { menuViewController.View.Frame = new CGRect { Location = new CGPoint { X = MenuDestinationXFromState(newMenuState), Y = 0f, }, Size = menuViewController.View.Frame.Size, }; menuViewController.SetPercentMaximized(shouldMaximize ? 1 : 0); menuBackgroundView.Alpha = shouldMaximize ? 1 : 0; }); menuAnimator.AddCompletion(pos => menuState = shouldMaximize ? MenuState.Open : MenuState.Closed); menuAnimator.StartAnimation(); }
void AnimateToRest() { var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.4f, response: 0.2f); var animator = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters); animator.AddAnimations(() => { Transform = CGAffineTransform.MakeScale(1, 1); BackgroundColor = isOn ? onColor : offColor; }); animator.Interruptible = true; animator.StartAnimation(); }
private void OpacityFull() { this.txtTitle.Text = this.apiResponse; Action setOpacityFull = () => { this.viewText.Alpha = 1; }; UIViewPropertyAnimator propertyAnimatorOpacityFull = new UIViewPropertyAnimator(4, UIViewAnimationCurve.EaseInOut, setOpacityFull); propertyAnimatorOpacityFull.StartAnimation(); }
public static void Animate(double duration, nfloat delay, CubicBezierCurve curve, Action changes, Action completion = null) { var propertyAnimator = new UIViewPropertyAnimator(duration, curve.ToCubicTimingParameters()); propertyAnimator.AddAnimations(changes, delay); if (completion != null) { propertyAnimator.AddCompletion(_ => completion()); } propertyAnimator.StartAnimation(); }
void AnimateView() { var timingParameters = UISpringTiming.MakeTimingParameters(damping: dampingRatio, response: frequencyResponse); animator = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters); animator.AddAnimations(() => { var translation = View.Bounds.Width - 2 * margin - 80; springView.Transform = CGAffineTransform.MakeTranslation(translation, 0); }); animator.AddCompletion((x) => { springView.Transform = CGAffineTransform.MakeIdentity(); AnimateView(); }); animator.StartAnimation(); }
public void Start(Flyover flyover) { // Set flyover _flyover = flyover; if (UIApplication.SharedApplication.ApplicationState != UIApplicationState.Active) { // Return out of function return; } // Change state State = FlyoverCameraState.Started; // Stop current animation _animator?.ForceStopAnimation(); // Set center coordinate _mapCamera.CenterCoordinate = flyover.Coordinate; // Check if duration is zero or the current mapView camera // equals nearly the same to the current flyover if (new Flyover(_mapView.Camera).NearlyEquals(_flyover)) { // Simply perform flyover as we are still looking at the same coordinate PerformFlyover(flyover); } else if (Configuration.RegionChangeAnimation == RegionChangeAnimation.Animated && Configuration.Duration > 0) { // Apply StartAnimationMode animated // Initialize start animator var startAnimator = new UIViewPropertyAnimator( duration: Configuration.Duration, curve: Curve, animations: () => { _mapView.Camera = _mapCamera; }); // Add completion startAnimator.SetCompletion((x) => PerformFlyover(_flyover)); // Start animation startAnimator.StartAnimation(); } else { // No animation should be applied // Set MapView Camera to look at coordinate _mapView.Camera = _mapCamera; // Perform flyover PerformFlyover(_flyover); } }
public override void ViewDidLoad() { base.ViewDidLoad(); imageView = new UIImageView(new CGRect(0, 100, 50, 50)); image = UIImage.FromFile("Sample.png"); imageView.Image = image; imageView.Alpha = 0.25f; View.AddSubview(imageView); Action setCenterRight = () => { var xpos = UIScreen.MainScreen.Bounds.Right - imageView.Frame.Width / 2; var ypos = imageView.Center.Y; imageView.Center = new CGPoint(xpos, ypos); }; Action setCenterLeft = () => { var xpos = UIScreen.MainScreen.Bounds.Left + imageView.Frame.Width / 2; var ypos = imageView.Center.Y; imageView.Center = new CGPoint(xpos, ypos); }; Action setOpacity = () => { imageView.Alpha = 1; }; UIViewPropertyAnimator propertyAnimator = new UIViewPropertyAnimator(4, UIViewAnimationCurve.EaseInOut, setCenterRight); propertyAnimator.AddAnimations(setOpacity); Action <object> reversePosition = (o) => { InvokeOnMainThread(() => { propertyAnimator.AddAnimations(setCenterLeft); }); }; TimerCallback abortPositionDelegate = new TimerCallback(reversePosition); Timer abortPosition = new Timer(abortPositionDelegate, null, 3000, Timeout.Infinite); propertyAnimator.StartAnimation(); }
void AnimatePullout(PulloutState newPulloutState, float initialVelocity = 0.7f, bool launchKeyboard = false) { var initialVelocityVector = new CGVector(0f, initialVelocity); var springParameters = GetSpringTimingParameters(initialVelocityVector); var destinationY = PulloutDestinationYFromState(newPulloutState); pulloutAnimator = new UIViewPropertyAnimator(0, springParameters) { Interruptible = true, }; pulloutAnimator.AddAnimations(() => { mainPulloutView.Frame = new CGRect { Location = new CGPoint { X = mainPulloutView.Frame.X, Y = destinationY, }, Size = mainPulloutView.Frame.Size, }; mainPulloutView.SetPercentMaximized(newPulloutState == PulloutState.Maximized ? 1 : 0); mainPulloutView.SetPercentMinimized(newPulloutState == PulloutState.Neutral || newPulloutState == PulloutState.Maximized ? 0 : 1); pulloutBackgroundView.Alpha = newPulloutState == PulloutState.Maximized ? 1 : 0; }); if (launchKeyboard) { mainPulloutView.LaunchKeyboard(); } pulloutAnimator.AddCompletion(pos => { pulloutState = newPulloutState; mainPulloutView.PulloutDidFinishAnimating(newPulloutState); }); pulloutAnimator.StartAnimation(); }
void Panned(NSObject r) { var recognizer = r as UIPanGestureRecognizer; var touchPoint = recognizer.LocationInView(View); var velocity = recognizer.VelocityInView(View); switch (recognizer.State) { case UIGestureRecognizerState.Began: originalTouchPoint = touchPoint; break; case UIGestureRecognizerState.Changed: var offset = touchPoint.Y - originalTouchPoint.Y; if (offset > 0) { offset = NMath.Pow(offset, 0.7f); } else if (offset < -verticalOffset * 2) { offset = -verticalOffset * 2 - NMath.Pow(-(offset + verticalOffset * 2f), 0.7f); } accelerationView.Transform = CGAffineTransform.MakeTranslation(0, offset); TrackPause(velocity.Y, offset); break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.8f, response: 0.3f); var animator = new UIViewPropertyAnimator(0, timingParameters); animator.AddAnimations(() => { accelerationView.Transform = CGAffineTransform.MakeIdentity(); pauseLabel.Alpha = 0; }); animator.Interruptible = true; animator.StartAnimation(); hasPaused = false; break; default: break; } }
private void StartAnimationIfNeeded() { if (animator.Running) { return; } var timingParameters = UISpringTiming.MakeTimingParameters(damping: 1, response: 0.4f); animator = new UIViewPropertyAnimator(0, timingParameters); animator.AddAnimations(() => { momentumView.Transform = isOpen ? closedTransform : CGAffineTransform.MakeIdentity(); }); animator.AddCompletion((position) => { if (position == UIViewAnimatingPosition.End) { isOpen = !isOpen; } }); animator.StartAnimation(); }
public void Stop() { // Change state State = FlyoverCameraState.Stopped; // Unwrap MapView Camera Heading and fractionComplete if (_mapView == null || _animator == null) { _animator?.ForceStopAnimation(); _animator = null; return; } var heading = _mapView.Camera.Heading; var fractionComplete = _animator.FractionComplete; // Force stop the animation _animator?.ForceStopAnimation(); // Initialize Animator with stop animation _animator = new UIViewPropertyAnimator( duration: 0, curve: Curve, animations: () => { // Subtract the HeadingStep from current heading to retrieve start value heading -= Configuration.HeadingStep; // Initialize the percentage of the completed heading step var percentageCompletedHeadingStep = (double)fractionComplete * Configuration.HeadingStep; // Set MapCamera Heading _mapCamera.Heading = (heading + percentageCompletedHeadingStep) % 360; // Set MapView Camera _mapView.Camera = _mapCamera; }); // Start animation _animator?.StartAnimation(); // Clear animator as animation has been handled _animator = null; }
protected virtual void OnShellSectionPropertyChanged(object sender, PropertyChangedEventArgs e) { if (_isDisposed) { return; } if (e.PropertyName == ShellSection.CurrentItemProperty.PropertyName) { var newContent = ShellSection.CurrentItem; var oldContent = _currentContent; if (newContent == null) { return; } if (_currentContent == null) { _currentContent = newContent; _currentIndex = ShellSectionController.GetItems().IndexOf(_currentContent); _tracker.Page = ((IShellContentController)newContent).Page; return; } var items = ShellSectionController.GetItems(); if (items.Count == 0) { return; } var oldIndex = _currentIndex; var newIndex = items.IndexOf(newContent); var oldRenderer = _renderers[oldContent]; // this means the currently visible item has been removed if (oldIndex == -1 && _currentIndex <= newIndex) { newIndex++; } _currentContent = newContent; _currentIndex = newIndex; if (!_renderers.ContainsKey(newContent)) { return; } var currentRenderer = _renderers[newContent]; _isAnimatingOut = oldRenderer; _pageAnimation?.StopAnimation(true); _pageAnimation = null; _pageAnimation = CreateContentAnimator(oldRenderer, currentRenderer, oldIndex, newIndex, _containerArea); if (_pageAnimation != null) { _pageAnimation.AddCompletion((p) => { if (_isDisposed) { return; } if (p == UIViewAnimatingPosition.End) { RemoveNonVisibleRenderers(); } }); _pageAnimation.StartAnimation(); } else { RemoveNonVisibleRenderers(); } } }
public override void ViewDidLoad() { base.ViewDidLoad(); imageView = new UIImageView(new CGRect(0, 100, 50, 50)); image = UIImage.FromBundle("Default.png"); imageView.Image = image; imageView.Alpha = 0.25f; View.AddSubview(imageView); Action setCenterRight = () => { var xpos = UIScreen.MainScreen.Bounds.Right - imageView.Frame.Width / 2; var ypos = imageView.Center.Y; imageView.Center = new CGPoint(xpos, ypos); }; Action setCenterLeft = () => { var xpos = UIScreen.MainScreen.Bounds.Left + imageView.Frame.Width / 2; var ypos = imageView.Center.Y; imageView.Center = new CGPoint(xpos, ypos); }; Action setOpacity = () => { imageView.Alpha = 1; }; UIViewPropertyAnimator propertyAnimator = new UIViewPropertyAnimator(4, UIViewAnimationCurve.EaseInOut, setCenterRight); propertyAnimator.AddAnimations(setOpacity); Action <object> reversePosition = (o) => { InvokeOnMainThread(() => { propertyAnimator.AddAnimations(setCenterLeft); }); }; TimerCallback abortPositionDelegate = new TimerCallback(reversePosition); Timer abortPosition = new Timer(abortPositionDelegate, null, 3000, Timeout.Infinite); propertyAnimator.StartAnimation(); // Perform any additional setup after loading the view, typically from a nib. /*layer = new CALayer(); * layer.Bounds = new CGRect(0, 0, 80, 80); * layer.Position = new CGPoint(100, 100); * layer.Contents = UIImage.FromBundle("Default.png").CGImage; * layer.ContentsGravity = CALayer.GravityResizeAspectFill; * * View.Layer.AddSublayer(layer); * * /*UIImageView imageView= new UIImageView(new CGRect(50, 50, 57, 57)); * UIImage image = UIImage.FromBundle("Default.png"); * imageView.Image = image; * View.AddSubview(imageView); * * CGPoint point = imageView.Center; * UIView.Animate(2, 0, UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.Autoreverse, * () => * { * imageView.Center = new CGPoint(UIScreen.MainScreen.Bounds.Right - imageView.Frame.Width / 2, imageView.Center.Y); * }, * () => * { * imageView.Center = point; * } * );*/ }
void LayoutSidebar(bool animate) { if (_gestureActive) { return; } if (animate && _flyoutAnimation != null) { return; } if (!animate && _flyoutAnimation != null) { _flyoutAnimation.StopAnimation(true); _flyoutAnimation = null; } if (Forms.IsiOS10OrNewer) { if (IsOpen) { UpdateTapoffView(); } if (animate && TapoffView != null) { var tapOffViewAnimation = CABasicAnimation.FromKeyPath(@"opacity"); tapOffViewAnimation.BeginTime = 0; tapOffViewAnimation.Duration = AnimationDurationInSeconds; tapOffViewAnimation.SetFrom(NSNumber.FromFloat(TapoffView.Layer.Opacity)); tapOffViewAnimation.SetTo(NSNumber.FromFloat(IsOpen ? 1 : 0)); tapOffViewAnimation.FillMode = CAFillMode.Forwards; tapOffViewAnimation.RemovedOnCompletion = false; _flyoutAnimation = new UIViewPropertyAnimator(AnimationDurationInSeconds, UIViewAnimationCurve.EaseOut, () => { FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior); if (TapoffView != null) { TapoffView.Layer.AddAnimation(tapOffViewAnimation, "opacity"); } }); _flyoutAnimation.AddCompletion((p) => { if (p == UIViewAnimatingPosition.End) { if (TapoffView != null) { TapoffView.Layer.Opacity = IsOpen ? 1 : 0; TapoffView.Layer.RemoveAllAnimations(); } UpdateTapoffView(); _flyoutAnimation = null; } }); _flyoutAnimation.StartAnimation(); View.LayoutIfNeeded(); } else if (_flyoutAnimation == null) { FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior); UpdateTapoffView(); if (TapoffView != null) { TapoffView.Layer.Opacity = IsOpen ? 1 : 0; } } } else { if (animate) { UIView.BeginAnimations(FlyoutAnimationName); } FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior); if (animate) { UIView.SetAnimationCurve(AnimationCurve); UIView.SetAnimationDuration(AnimationDurationInSeconds); UIView.CommitAnimations(); View.LayoutIfNeeded(); } UpdateTapoffView(); } void UpdateTapoffView() { if (IsOpen && _flyoutBehavior == FlyoutBehavior.Flyout) { AddTapoffView(); } else { RemoveTapoffView(); } } }