|
12 | 12 | "$DIALOG" tooltip --html '<h1>‘foobar’</h1>'
|
13 | 13 | */
|
14 | 14 |
|
15 |
| -static CGFloat slow_in_out (CGFloat t) |
16 |
| -{ |
17 |
| - if(t < 1.0) |
18 |
| - t = 1.0 / (1.0 + exp((-t*12.0)+6.0)); |
19 |
| - return std::min(t, 1.0); |
20 |
| -} |
21 |
| - |
22 | 15 | NSString* const TMDTooltipPreferencesIdentifier = @"TM Tooltip";
|
23 | 16 |
|
24 | 17 | @interface TMDHTMLTip ()
|
25 | 18 | - (void)setContent:(NSString*)content transparent:(BOOL)transparent;
|
26 | 19 | - (void)runUntilUserActivity:(id)sender;
|
27 |
| -- (void)stopAnimation:(id)sender; |
28 | 20 | @end
|
29 | 21 |
|
30 | 22 | @implementation TMDHTMLTip
|
@@ -200,45 +192,27 @@ - (void)runUntilUserActivity:(id)sender
|
200 | 192 | [keyWindow setAcceptsMouseMovedEvents:didAcceptMouseMovedEvents];
|
201 | 193 |
|
202 | 194 |
|
203 |
| - [self orderOut:self]; |
| 195 | + [self fadeOut:self]; |
204 | 196 | }
|
205 | 197 |
|
206 | 198 | // =============
|
207 | 199 | // = Animation =
|
208 | 200 | // =============
|
209 |
| -- (void)orderOut:(id)sender |
| 201 | +- (void)fadeOut:(id)sender |
210 | 202 | {
|
211 |
| - if(![self isVisible] || animationTimer) |
212 |
| - return; |
| 203 | + [NSAnimationContext beginGrouping]; |
213 | 204 |
|
214 |
| - [self stopAnimation:self]; |
215 |
| - [self setValue:[NSDate date] forKey:@"animationStart"]; |
216 |
| - [self setValue:[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(animationTick:) userInfo:nil repeats:YES] forKey:@"animationTimer"]; |
217 |
| -} |
| 205 | + [NSAnimationContext currentContext].duration = 0.5; |
| 206 | + [NSAnimationContext currentContext].completionHandler = ^{ |
| 207 | + [self orderOut:self]; |
| 208 | + }; |
218 | 209 |
|
219 |
| -- (void)animationTick:(id)sender |
220 |
| -{ |
221 |
| - CGFloat alpha = 0.97 * (1.0 - slow_in_out(-1.5 * [animationStart timeIntervalSinceNow])); |
222 |
| - if(alpha > 0.0) |
223 |
| - { |
224 |
| - [self setAlphaValue:alpha]; |
225 |
| - } |
226 |
| - else |
227 |
| - { |
228 |
| - [super orderOut:self]; |
229 |
| - [self stopAnimation:self]; |
230 |
| - [self close]; |
231 |
| - } |
232 |
| -} |
| 210 | + CABasicAnimation* anim = [CABasicAnimation animation]; |
| 211 | + anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; |
| 212 | + self.animations = @{ @"alphaValue" : anim }; |
233 | 213 |
|
234 |
| -- (void)stopAnimation:(id)sender; |
235 |
| -{ |
236 |
| - if(animationTimer) |
237 |
| - { |
238 |
| - [animationTimer invalidate]; |
239 |
| - [self setValue:nil forKey:@"animationTimer"]; |
240 |
| - [self setValue:nil forKey:@"animationStart"]; |
241 |
| - [self setAlphaValue:0.97]; |
242 |
| - } |
| 214 | + [self.animator setAlphaValue:0]; |
| 215 | + |
| 216 | + [NSAnimationContext endGrouping]; |
243 | 217 | }
|
244 | 218 | @end
|
0 commit comments