I have a simple animation that runs when a message is received. This works great if they are only receive one message. However if the user receives multiple messages within the animation, the animation starts over. I don't want this to happen though, I want the animation to finish before starting the next one. My thinking was to create some sort of queue that will loop through a dictionary with keys 'from' and 'body' but I am not sure if this is the best practice. Does anyone have any ideas?
- (void) messageReceived:(NSNotification *)notification
{
NSString *body = [[notification userInfo] valueForKey:@"body"];
NSString *from = [[notification userInfo] valueForKey:@"from"];
UILabel *usernameLabel = (UILabel *)[self.view viewWithTag:502];
usernameLabel.text = from;
UILabel *messageLabel = (UILabel *)[self.view viewWithTag:503];
messageLabel.text = body;
CGRect notificationFrame = notificationView.frame;
notificationFrame.origin.y = 0;
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
notificationView.frame = notificationFrame;
}
completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.3
delay:1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect oldNotificationFrame = notificationView.frame;
oldNotificationFrame.origin.y = -100;
notificationView.frame = oldNotificationFrame;
}
completion:NULL];
}
}];
}