animations: fix glitch after animations
After animations, the animated view came back to its original position before
properly being updated. We now set its new position right before the animation
Refs #75600
Change-Id: I1bcd4e95a831c1d5b301a6b1f8b7afee44132a29
diff --git a/src/PreferencesVC.mm b/src/PreferencesVC.mm
index 26f11d8..9edb1a6 100644
--- a/src/PreferencesVC.mm
+++ b/src/PreferencesVC.mm
@@ -68,18 +68,21 @@
// Set the layer redraw policy. This would be better done in
// the initialization method of a NSView subclass instead of here.
- self.view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize;
+ self.view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
[self.view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height);
- CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
- animation.fromValue = [NSValue valueWithPoint:frame.origin];
- animation.toValue = [NSValue valueWithPoint:self.view.frame.origin];
+ [CATransaction begin];
+ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
+ animation.fromValue = @(frame.origin.y);
+ animation.toValue = @(self.view.frame.origin.y);
animation.duration = 0.3f;
+
[animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]];
[self.view.layer addAnimation:animation forKey:animation.keyPath];
+ [CATransaction commit];
}
- (void) close
@@ -96,9 +99,9 @@
CGRect frame = CGRectOffset(self.view.frame, 0, -self.view.frame.size.height);
[CATransaction begin];
- CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
- animation.fromValue = [NSValue valueWithPoint:self.view.frame.origin];
- animation.toValue = [NSValue valueWithPoint:frame.origin];
+ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
+ animation.fromValue = @(self.view.frame.origin.y);
+ animation.toValue = @(frame.origin.y);
animation.duration = 0.3f;
[animation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:.7 :0.9 :1 :1]];
@@ -106,8 +109,10 @@
[self.view removeFromSuperview];
}];
-
[self.view.layer addAnimation:animation forKey:animation.keyPath];
+
+ // set final layer position to prevent glitching back to original one
+ [self.view.layer setPosition:frame.origin];;
[CATransaction commit];
}