Animations not starting directly after method call
In my app delegate I perform my updateData
method using performSelecorInBackground:withObject
. At the end, a notification is posted which tells an observer in my tableview to reload the data.
My problem is with the animations: using the code below, my animations start at the end of the method and not directly after performSelector
.
Does this have something to do with backgrounding the selector or is there something else I'm not seeing?
Any help would be greatly appreciated.
Thanks!
- (void) updateData: (NSString *)newVersionNumber {
... CODE ...
UIView *update = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 360, 20)];
update.backgroundColor = [UIColor blackColor];
[self.navController.view addSubview:update];
[self performSelector:@selector(updateDownAnimation) withObject:nil];
... CODE ...
[[NSNotificationCenter defaultCenter] p开发者_如何学JAVAostNotificationName:@"tableviewShouldReload" object:nil];
... CODE ...
[self performSelector:@selector(updateUpAnimation) withObject:nil];
}
- (void) updateDownAnimation {
[UIView animateWithDuration:0.3 animations:^{
_window.frame = CGRectOffset(_window.frame, 0, 20);
}];
}
It is not advisable to do UIKit stuff on secondary threads. You might want to change that to
[self performSelectorOnMainThread:@selector(updateUpAnimation)
withObject:nil
waitUntilDone:YES];
精彩评论