Reputation: 1497
So I have this code moving an NSButton to the coordinates listed
[[MyNSButton animator] setFrame:NSMakeRect(567, 228, 109, 151)];
Then I have the same code moving another NSButton
[[MyNSButton2 animator] setFrame:NSMakeRect(695, 228, 109, 151)];
What I want to do is have the first statement execute, and then when the entire animation is over, and after a delay of maybe .5 seconds, have the next one go. How can I do that?
Upvotes: 2
Views: 7010
Reputation: 2592
You need to use NSTimer
Here is the code how to do that
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(getnextButton) userInfo:nil repeats:NO];
where getnextButton
is the method that would be called after .5 seconds.
put the code in this method which you want to execute after .5 seconds.
Hope this would help you.
Upvotes: 9
Reputation: 337
I thing this kind of codes will be helpful. make a new queue (thread) and make it sleep! Thats it...
dispatch_async(dispatch_queue_create("loadqueue", nil), ^{ [NSThread sleepForTimeInterval:2]; //codes here... });
Upvotes: 1
Reputation: 2592
If you simply want to delay code execution then you can let the main thread sleep using this:
[NSThread sleepForTimeInterval:5.0];
This will delay the thread for 5 seconds and then the execution would start.Put this statement where you want the delay. Hope this would help you.
Upvotes: 4
Reputation: 2592
Or you can do this as well but again you need to take method for that.
[self performSelector:@selector(onGeocoding:) withObject:nil afterDelay:60.0];
Upvotes: 11
Reputation: 61248
You'll want to look into the Animation Programming Guide for Cocoa, specifically the Setting and Handling Progress Marks section. When the animation finishes moving to the second rect, trigger moving back to the first; when it's back to the first, trigger moving to the second, ad infinitum.
Upvotes: 1