In my iOS application, when a button is clicked, an event is triggered, and a status message appears at the bottom of the screen informing the user about the success or failure of the operation.
A status message appears and disappears with the following code.
this will display a message
- (void) showMessage:(NSString*)text { CGRect frame = [[self view] frame]; if(statusView == nil) { messageViewWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, frame.size.height-29, frame.size.width, 0)]; statusView = [[StatusMessageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 0) Text:text andShowIndicator:NO]; [messageViewWindow addSubview:statusView]; [messageViewWindow makeKeyAndVisible]; } UILabel *label = [statusView getTextLabel]; UIImageView *imageView = [statusView getBackImageView]; CGSize stringSize = [text sizeWithFont:[Constants getLabelFont]]; int xCoordinate = (messageViewWindow.frame.size.width - stringSize.width)/2; [UIView beginAnimations:nil context:nil]; messageViewWindow.frame = CGRectMake(0, frame.size.height-59, frame.size.width, 30); statusView.frame = CGRectMake(0, 0, frame.size.width, 30); label.frame = CGRectMake(xCoordinate,5,stringSize.width,20); imageView.frame = CGRectMake(0, 0, frame.size.width, 30); [UIView commitAnimations]; [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(hideMessage) userInfo:nil repeats:NO]; }
and it hides the message
- (void) hideMessage { UILabel *label = [statusView getTextLabel]; UIImageView *imageView = [statusView getBackImageView]; CGRect labelFrame = label.frame; [UIView beginAnimations:nil context:nil]; messageViewWindow.frame = CGRectMake(0, [UIScreen mainScreen].applicationFrame.size.height-29, [UIScreen mainScreen].applicationFrame.size.width, 0); statusView.frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, 0); label.frame = CGRectMake(labelFrame.origin.x, 0, labelFrame.origin.y, 0); imageView.frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, 0); [UIView commitAnimations]; }
it is strange that the message is displayed and disappears after two seconds, but the main window loses its functionality, for example, the ability to copy and paste.
Do you see something wrong in my methods? Is there any specific way that calls the animation code?