Created
February 16, 2013 13:52
-
-
Save hetima/4967007 to your computer and use it in GitHub Desktop.
runAnimationGroup and dispatch_after
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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