ios - 弹出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/

相关文章:

ios - Amazon S3 iOS SDK v2 使用 AWSAccessKeyId :Signature 上传

ios - 如何在 TableView 中的可变数组中存储多个选定的行项

ios - Xcode 5 调试器不打印对象

iphone - 转换sql语句以用于核心数据

ios - 如何消除文本字段中某个字符的出现并使其仅出现在前缀处

iphone - 将 xcode 4.6 iPhone 应用程序转换为通用应用程序

ios - SpriteKit 中的毛玻璃效果?

ios - 如何在 Swift 中正确转换为子类?

ios - 从 JTSImageViewController 解除时重置 View

objective-c - 显示 UITableViewCell,然后可以展开以显示更多数据