本文介绍如何实现自动关闭的UIAlertView,类似Android的Toast效果。
废话不多说,直接上代码:
- (void)alertCenter:(NSString *)message
{
NSString *title = @"AlertTitle";
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
// dismiss after 3 seconds
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 3ull * NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^{
[alert dismissWithClickedButtonIndex:0 animated:NO];
});
}
本文介绍了一种在 iOS 应用中实现 UIAlertView 自动关闭的方法,类似于 Android 的 Toast 效果。通过使用 GCD (Grand Central Dispatch) 来实现延迟关闭,确保了对话框能够按预期的时间自动消失。

2758

被折叠的 条评论
为什么被折叠?



