本文介绍了弹出1秒钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
向用户实施文字+图片信息的常规(或最佳)方式是什么,而这个提示/弹出应该只出现1秒钟(如有限时间内的奖品图片上的消息You Won!时间)。
What is the regular (or best) way to implement text+image message to user, while this "alert/pop-up" should appear only for 1 second (like message "You Won!" on Prize picture for limited period of time).
推荐答案
如果您只想在一段时间内显示浮动消息并让它逐渐消失,只需制作一个标签和一个简单的动画。此示例将显示消息1秒,然后消退0.3秒(并假设为ARC):
If you just want to show a floating message for a little bit of time and have it fade away, just make a label and a simple animation. This example will show the message for 1 second then fade away over 0.3 seconds (and assumes 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 on your root view.
这篇关于弹出1秒钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!