Popup for 1 second

What is the usual (or best) way to implement a text message + image to the user, while this “warning / popup” should only appear for 1 second (for example, the message “You Won!” On the Prize image for a limited period of time) .

+4
source share
2 answers

If you just want to show a floating message for a little while and fade away, just make a shortcut and simple animation. In this example, the message will be displayed for 1 second and then disappear after 0.3 seconds (and will accept ARC):

- (void)showMessage:(NSString*)message atPoint:(CGPoint)point { const CGFloat fontSize = 24; // Or whatever. UILabel* label = [[UILabel alloc] initWithFrame:CGRectZero]; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize]; // Or whatever. label.text = message; label.textColor = [UIColor blueColor]; // Or whatever. [label sizeToFit]; label.center = point; [self addSubview:label]; [UIView animateWithDuration:0.3 delay:1 options:0 animations:^{ label.alpha = 0; } completion:^(BOOL finished) { label.hidden = YES; [label removeFromSuperview]; }]; } 

Just add this as a method to your root mode.

+15
source

If you do not want user interaction, go to HUD.

Good implementations there are SVProgressHUD and MBProgressHUD

They are usually designed to progress, but you can use them to display temporary information to the user.

As an example, here you can easily display a 1 second message along with a custom image using SVProgressHUD :

 [SVProgressHUD showImage:[UIImage imageNamed:@"won-image"] status:@"You Won!"]; 
+1
source

Source: https://habr.com/ru/post/1499242/


All Articles