Skip to content

Instantly share code, notes, and snippets.

@hetima hetima/gist:4967007
Created Feb 16, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.