Skip to content

Instantly share code, notes, and snippets.

@hetima
Created February 16, 2013 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hetima/4967007 to your computer and use it in GitHub Desktop.
Save hetima/4967007 to your computer and use it in GitHub Desktop.
runAnimationGroup and dispatch_after
+ (void)showNotificationString:(NSString*)label inView:(NSView*)parentView
{
NSRect frame=parentView.frame;
frame.origin=NSZeroPoint;
frame.size.height=20;
frame.origin.y-=frame.size.height;
DTNotificationView* noteView=[[DTNotificationView alloc]initWithFrame:frame];
noteView.label=label;
[parentView addSubview:noteView];
frame.origin.y=0;
//出現して
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
[[noteView animator]setFrame:frame];
} completionHandler:^{
double delayInSeconds = 3.0; // 3秒後
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//消える
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
//context.duration=0.33f;
context.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
NSRect outRect=noteView.frame;
outRect.origin.y-=outRect.size.height;
[[noteView animator]setFrame:outRect];
//[[noteView animator]setAlphaValue:0.0f];
} completionHandler:^{[noteView removeFromSuperview];}];
});
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment