<分区>
向用户实现文本+图像消息的常规(或最佳)方式是什么,而此“警报/弹出窗口”应仅显示 1 秒(如限时奖品图片上的消息“您赢了!”的时间)。
标签 ios objective-c
<分区>
向用户实现文本+图像消息的常规(或最佳)方式是什么,而此“警报/弹出窗口”应仅显示 1 秒(如限时奖品图片上的消息“您赢了!”的时间)。
最佳答案
如果您只想显示一条 float 消息一段时间然后让它逐渐消失,只需制作一个标签和一个简单的动画即可。此示例将显示消息 1 秒,然后在 0.3 秒内逐渐消失(并假定 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];
}];
}
只需将其作为方法添加到您的 Root View 中即可。
关于ios - 弹出1秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18475850/