protected virtual void Window_DidResize(object sender, EventArgs e) { var rect = VisibleRect(); // resize and reposition all layers to match the window var frame = GetRect(rect.Width, rect.Height); CATransaction.Begin(); CATransaction.DisableActions = true; CATransaction.AnimationDuration = 0; Layer.Frame = frame; nfloat width = frame.Width; nfloat height = frame.Height; CGRect subFrame = new CGRect(0, 0, width, height); foreach (CALayer layer in Layer.Sublayers) { layer.Frame = subFrame; layer.SetNeedsDisplay(); } CATransaction.Commit(); }
void ResetLayerValues(bool desireSelectedState, bool stateWillBeAnimated) { CATransaction.Begin(); CATransaction.DisableActions = true; if ((desireSelectedState && stateWillBeAnimated) || (!desireSelectedState && !stateWillBeAnimated)) { // Switch to deselected state checkmark.StrokeEnd = 0; checkmark.StrokeStart = 0; trailCircle.Opacity = 0; circle.StrokeStart = 0; circle.StrokeEnd = 1; } else { // Switch to selected state checkmark.StrokeEnd = finalStrokeEndForCheckmark; checkmark.StrokeStart = finalStrokeStartForCheckmark; trailCircle.Opacity = 1; circle.StrokeStart = 0; circle.StrokeEnd = 0; } CATransaction.Commit(); }
public override bool ContinueTracking(UITouch uitouch, UIEvent uievent) { CGPoint touchPoint = uitouch.LocationInView(this); nfloat delta = touchPoint.X - previousTouchPoint.X; nfloat valueDelta = (maxValue - minValue) * delta / usableTrackLength; previousTouchPoint = touchPoint; if (lowerKnobLayer.Highlight) { lowerValue += valueDelta; lowerValue = LimitBounds(lowerValue, minValue, upperValue); } else if (upperKnobLayer.Highlight) { upperValue += valueDelta; upperValue = LimitBounds(upperValue, lowerValue, maxValue); } CATransaction.Begin(); CATransaction.DisableActions = true; SetLayerFrames(); CATransaction.Commit(); OnRangeChanged(); return(true); }
public override void LayoutSubviews() { base.LayoutSubviews(); // Disable CoreAnimation actions so that the positions of the sublayers immediately move to their new position. CATransaction.Begin(); CATransaction.DisableActions = true; // Create the path for the mask layer. We use the even odd fill rule so that the region of interest does not have a fill color. var path = UIBezierPath.FromRect(new CGRect(0, 0, Frame.Width, Frame.Height)); path.AppendPath(UIBezierPath.FromRect(RegionOfInterest)); path.UsesEvenOddFillRule = true; maskLayer.Path = path.CGPath; regionOfInterestOutline.Path = CGPath.FromRect(RegionOfInterest); var r = RegionOfInterestControlRadius; topLeftControl.Position = RegionOfInterest.CornerTopLeft().WithOffsetX(-r).WithOffsetY(-r); topRightControl.Position = RegionOfInterest.CornerTopRight().WithOffsetX(-r).WithOffsetY(-r); bottomLeftControl.Position = RegionOfInterest.CornerBottomLeft().WithOffsetX(-r).WithOffsetY(-r); bottomRightControl.Position = RegionOfInterest.CornerBottomRight().WithOffsetX(-r).WithOffsetY(-r); CATransaction.Commit(); }
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(); }
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(); }
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(); }
public override void UpdateLayer() { if (!animateChanges) { CATransaction.Begin(); CATransaction.DisableActions = true; } var width = Layer.Bounds.Width; var progressX = Layer.Bounds.Width * progress; var midY = Layer.Bounds.GetMidY(); backgroundLayer.Frame = new CGRect(0, midY - 1, Layer.Bounds.Width, 3.0f); filledLayer.Frame = new CGRect(0, midY - 1, progressX, 3.0f); progressHandleLayer.Opacity = (showProgressHandle || IsDragging ? 1 : 0); progressHandleLayer.Position = new CGPoint(progressX, midY); if (!animateChanges) { CATransaction.Commit(); } animateChanges = true; }
private void SetSelected(bool newValue, bool isAnimated) { if (Selected == newValue) { return; } Selected = newValue; CATransaction.Begin(); CATransaction.AnimationDuration = isAnimated ? 0.2f : 0f; if (Selected) { ShapeAnimation(shapeLayer, KeyPathStrokeEnd, null, new NSNumber(1.0)); ShapeAnimation(shapeLayer, KeyPathBackgroundColor, null, NSObject.FromObject(ColorPallete.Blue.CGColor)); BorderColor = UIColor.White; } else { CATransaction.Begin(); CATransaction.AnimationDuration = 0f; ShapeAnimation(shapeLayer, KeyPathStrokeEnd, null, new NSNumber(1)); CATransaction.Commit(); ShapeAnimation(shapeLayer, KeyPathBackgroundColor, null, FromObject(UIColor.White.CGColor)); BorderColor = ColorPallete.Gray; } CATransaction.Commit(); }
public override void LayoutSubviews() { base.LayoutSubviews(); // Disable CoreAnimation actions so that the positions of the sublayers immediately move to their new position. CATransaction.Begin(); CATransaction.DisableActions = true; // Create the path for the mask layer. We use the even odd fill rule so that the region of interest does not have a fill color. var path = UIBezierPath.FromRect(new CGRect(0, 0, this.Frame.Width, this.Frame.Height)); path.AppendPath(UIBezierPath.FromRect(this.RegionOfInterest)); path.UsesEvenOddFillRule = true; this.maskLayer.Path = path.CGPath; this.regionOfInterestOutline.Path = CGPath.FromRect(this.RegionOfInterest); var left = this.RegionOfInterest.X - this.RegionOfInterestControlRadius; var right = this.RegionOfInterest.X + this.RegionOfInterest.Width - this.RegionOfInterestControlRadius; var top = this.RegionOfInterest.Y - this.RegionOfInterestControlRadius; var bottom = this.RegionOfInterest.Y + this.RegionOfInterest.Height - this.RegionOfInterestControlRadius; this.topLeftControl.Position = new CGPoint(left, top); this.topRightControl.Position = new CGPoint(right, top); this.bottomLeftControl.Position = new CGPoint(left, bottom); this.bottomRightControl.Position = new CGPoint(right, bottom); CATransaction.Commit(); }
public static void dismissGlobalHUD() { UIWindow window = UIApplication.SharedApplication.KeyWindow; MBProgressHUD.HideAllHUDsForView(window, true); CATransaction.Commit(); }
void updateBackground() { var location = WuClient.Shared.Selected; var random = location == null || Settings.RandomBackgrounds; var layer = View.Layer.Sublayers [0] as CAGradientLayer; if (layer == null) { layer = new CAGradientLayer(); layer.Frame = View.Bounds; View.Layer.InsertSublayer(layer, 0); } var gradients = location.GetTimeOfDayGradient(random); if (layer?.Colors?.Length > 0 && layer.Colors [0] == gradients.Item1 [0] && layer.Colors [1] == gradients.Item1 [1]) { return; } CATransaction.Begin(); CATransaction.AnimationDuration = 1.5; layer.Colors = gradients.Item1; CATransaction.Commit(); }
public void UpdateProgress(double progress) { CATransaction.Begin(); CATransaction.SetValueForKey(new NSNumber(true), CATransaction.DisableActionsKey); ShapeLayer.StrokeEnd = (nfloat)progress; CATransaction.Commit(); }
/// <summary> /// Update the underlying controls as needed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (GradientLayer != null && GradientContentView != null) { // Turn off Animations CATransaction.Begin(); CATransaction.DisableActions = true; if (e.PropertyName == CustomGradientContentView.StartColorProperty.PropertyName) GradientLayer.Colors[0] = GradientContentView.StartColor.ToCGColor(); if (e.PropertyName == CustomGradientContentView.EndColorProperty.PropertyName) GradientLayer.Colors[1] = GradientContentView.EndColor.ToCGColor(); if (e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName) GradientLayer.Frame = NativeView.Bounds; if (e.PropertyName == CustomGradientContentView.OrientationProperty.PropertyName) SetOrientation(); CATransaction.Commit(); } }
protected void RepositionLayer(System.Drawing.RectangleF newPosition, bool parentHidden) { if (_layer != null) { bool newHidden = parentHidden || !Visible; if (newHidden != _layer.Hidden) { // If we're changing the visibility, disable animations since // the old rectangle for the position was probably wrong, resulting in // weird animation as it's repositioned. CATransaction.Begin(); CATransaction.DisableActions = true; _layer.Hidden = newHidden; _layer.Frame = newPosition; CATransaction.Commit(); } else { if (!_layer.Hidden) { _layer.Frame = newPosition; } } } }
void UpdateColors() { CGColor[] gradientColors; if (_Gradient != null && !Outline) { gradientColors = new CGColor[] { _Gradient.Start.ToUIColor().CGColor, _Gradient.End.ToUIColor().CGColor }; } else { gradientColors = new CGColor[] { UIColor.Clear.CGColor, UIColor.Clear.CGColor }; } CATransaction.Begin(); CATransaction.DisableActions = true; if (Outline) { Layer.BorderWidth = 1; Layer.BorderColor = OutlineColor.CGColor; if (Label != null) { Label.TextColor = OutlineColor; } } else { Layer.BorderWidth = 0; Layer.BorderColor = UIColor.Clear.CGColor; if (Label != null) { Label.TextColor = UIColor.White; } } GradientLayer.Colors = gradientColors; CATransaction.Commit(); }
// http://bugzilla.xamarin.com/show_bug.cgi?id=328 public void Bug328_CompletionBlock() { CATransaction.Begin(); CATransaction.CompletionBlock = delegate {}; // the above should not crash with a MonoTouchException CATransaction.Commit(); }
void updateBackground() { /* c0lby: Set the weather's conditional 'overlays' as the layers content prop by * supplying a delegate for the layer or subclassing. This will improve performance */ var location = WuClient.Shared.Selected; var random = location == null || Settings.RandomBackgrounds; var layer = View.Layer.Sublayers [0] as CAGradientLayer; if (layer == null) { layer = new CAGradientLayer(); layer.Frame = View.Bounds; View.Layer.InsertSublayer(layer, 0); } var gradients = location.GetTimeOfDayGradient(random); if (layer?.Colors?.Length > 0 && layer.Colors [0] == gradients.Item1 [0] && layer.Colors [1] == gradients.Item1 [1]) { return; } CATransaction.Begin(); CATransaction.AnimationDuration = 1.5; layer.Colors = gradients.Item1; CATransaction.Commit(); }
/// <summary> /// Reloads the layer. /// </summary> private void ReloadLayer() { CATransaction.Begin(); CATransaction.AnimationDuration = kAnimationDuration; // ------------------------------- Animate Colors if ((mDragged && mDraggingTowardsOn) || (!mDragged && mOn)) { mBackgroundLayer.BorderColor = this.TintColor.CGColor; mBackgroundLayer.BackgroundColor = this.TintColor.CGColor; } else { mBackgroundLayer.BorderColor = kDisabledBorderColor.CGColor; mBackgroundLayer.BackgroundColor = kDisabledBackgroundColor.CGColor; } // ------------------------------- Animate Enabled-Disabled state mRootLayer.Opacity = (Enabled) ? kEnabledOpacity : kDisabledOpacity; // ------------------------------- Animate Frame if (!mDragged) { var function = CAMediaTimingFunction.FromControlPoints(0.25f, 1.5f, 0.5f, 1.0f); CATransaction.AnimationTimingFunction = function; } mKnobLayer.Frame = RectForKnob(); mKnobInsideLayer.Frame = mKnobLayer.Bounds; CATransaction.Commit(); }
public void SetCurrentIndex(int index, bool animated) { if (ItemsCounts > 0 && ItemsCounts > index && index >= 0) { _delegate?.OnboardingWillTransitonToIndex(index); CurrentIndex = index; CATransaction.Begin(); CATransaction.CompletionBlock = () => _delegate?.OnboardingDidTransitonToIndex(index); var position = pageView?.PositionItemIndex(index, this); if (position != null) { fillAnimationView?.FillAnimation(GetItemColor(CurrentIndex), position.Value, 0.5); } pageView?.CurrentIndex(index, animated); contentView?.CurrentItem(index, animated); CATransaction.Commit(); } else if (index >= ItemsCounts) { _delegate?.OnboardingWillTransitonToLeaving(); } }
public override void OnAnimateCameraRequest(CameraUpdateMessage m) { _isCancelAnimate = _isAnimate; CATransaction.Begin(); if (m.Duration.HasValue) { CATransaction.AnimationDuration = m.Duration.Value.TotalSeconds; } CATransaction.CompletionBlock = () => { _isAnimate = false; if (_isCancelAnimate) { m.Callback.OnCanceled(); } else { m.Callback.OnFinished(); } _isCancelAnimate = false; }; _nativeMap.Animate(m.Update.ToIOS()); _isAnimate = true; _raiseWillMoveFromMethod = true; CATransaction.Commit(); }
private void StartAnimatingTransaction() { CATransaction.Begin(); float M_PI_2 = ((float)(Math.PI)) / 2.0f; CGAffineTransform tnull = CGAffineTransform.MakeIdentity(); CGPath circlePath = new CGPath(); circlePath.MoveToPoint(tnull, Frame.Width / 2.0f, Frame.Height - circleSize / 2.0f); circlePath.AddArc(tnull, Frame.Width / 2.0f, Frame.Height / 2.0f, radius - 15 / 2, M_PI_2, -M_PI_2 * 3, false); for (int i = 0; i < Layer.Sublayers.Length; i++) { CALayer circleLayer = Layer.Sublayers[i]; CAKeyFrameAnimation circleAnimation = CAKeyFrameAnimation.GetFromKeyPath("position"); circleAnimation.BeginTime = CAAnimation.CurrentMediaTime() + 0.2f * i; circleAnimation.Duration = 1.5; circleAnimation.TimingFunction = CAMediaTimingFunction.FromControlPoints(0.15f, 0.60f, 0.85f, 0.4f); circleAnimation.CalculationMode = CAKeyFrameAnimation.AnimationPaced; circleAnimation.Path = circlePath; circleAnimation.RepeatCount = float.MaxValue; if (circleLayer == this.Layer.Sublayers[Layer.Sublayers.Length - 1]) { circleAnimation.WeakDelegate = this; } circleLayer.AddAnimation(circleAnimation, "circleAnimation"); } //CGPathRelease(circlePath); CATransaction.Commit(); }
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(); }
public void ShowAnimated(bool animated) { if (!animated) { Layer.Opacity = 1.0f; return; } CATransaction.Begin(); { // start the transform animation from scale 0.5, or its current value if it's already running NSObject fromValue = Layer.AnimationForKey("transform") != null ? Layer.PresentationLayer.ValueForKey(new NSString("transform")) : NSValue.FromCATransform3D(CATransform3D.MakeScale(0.5f, 0.5f, 1)); Layer.AnimateKey(new NSString("transform"), fromValue, NSValue.FromCATransform3D(CATransform3D.Identity), (animation) => { animation.Duration = 0.4; animation.TimingFunction = CAMediaTimingFunction.FromControlPoints(0.8f, 2.5f, 0.35f, 0.5f); }); Layer.AnimateKey(new NSString("opacity"), null, NSObject.FromObject(1.0), (animation) => { animation.Duration = 0.1; }); } CATransaction.Commit(); }
private void AnimateTransitionForDismiss(IUIViewControllerContextTransitioning transitionContext) { var source = transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey); var destination = transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey); source.ViewWillDisappear(true); destination.ViewWillAppear(true); var duration = TransitionDuration(transitionContext); CATransaction.Begin(); CATransaction.CompletionBlock = () => { transitionContext.CompleteTransition(true); }; UIView.Animate(duration, 0, new UIViewAnimationOptions(), animation: () => { source.View.Alpha = 0; }, completion: () => { destination.ViewDidAppear(true); source.ViewDidDisappear(true); }); SpotlightTransitionWillDismiss?.Invoke(this, transitionContext); CATransaction.Commit(); }
private void AnimateTransitionForPresent(IUIViewControllerContextTransitioning transitionContext) { var source = transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey); var destination = transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey); transitionContext.ContainerView.InsertSubviewAbove(destination.View, source.View); destination.View.Alpha = 0; source.ViewWillDisappear(true); destination.ViewWillAppear(true); var duration = TransitionDuration(transitionContext); CATransaction.Begin(); CATransaction.CompletionBlock = () => { transitionContext.CompleteTransition(true); }; UIView.Animate(duration, 0, new UIViewAnimationOptions(), () => { destination.View.Alpha = (nfloat)1.0; }, () => { destination.ViewDidAppear(true); source.ViewDidDisappear(true); }); SpotlightTransitionWillPresent?.Invoke(this, transitionContext); CATransaction.Commit(); }
public static void showGlobalProgressHUDWithTitle(string title) { UIWindow window = UIApplication.SharedApplication.KeyWindow; MBProgressHUD hud = MBProgressHUD.ShowHUDAddedTo(window, true); hud.LabelText = title; CATransaction.Commit(); }
private static void AnimateMarker(CLLocationCoordinate2D position, Marker marker) { CATransaction.Begin(); CATransaction.AnimationDuration = AnimationDuration; marker.Layer.Latitude = position.Latitude; marker.Layer.Longitude = position.Longitude; CATransaction.Commit(); }
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator) { base.ViewWillTransitionToSize(toSize, coordinator); CATransaction.Begin(); CATransaction.DisableActions = true; coordinator.AnimateAlongsideTransition(ctx => { }, ctx => CATransaction.Commit()); }
public void RecenterToPosition(CLLocationCoordinate2D position) { CATransaction.Begin(); Foundation.NSNumber nsobj = Foundation.NSNumber.FromFloat(1.5f); CATransaction.SetValueForKey(nsobj, CATransaction.AnimationDurationKey); this.Animate(CameraPosition.FromCamera(position.Latitude, position.Longitude, Camera.Zoom)); CATransaction.Commit(); }