我使用类似于android toast的东西向用户发送消息。
这个敬酒词显示在当前视图中,在这种情况下,我想要更改视图,并且没有时间阅读消息。
因此,我使用一个线程在当前视图中停留了3秒钟,但toast也被延迟了。
[theHoleView makeToast:@"OK!!" duration:3 position:@"center" image:[UIImage imageNamed:@"nocorrect.png"]];
[NSThread sleepForTimeInterval:3];
[self.navigationController popToRootViewControllerAnimated:YES];我在Toast之后执行NSThread,为什么toast延迟了?
提前谢谢你
发布于 2012-09-17 18:48:30
这是因为你还没有回到绘制屏幕的主循环中。您可以使用[CATransaction flush]刷新图形上下文,例如
[theHoleView makeToast:@"OK!!" duration:3 position:@"center" image:[UIImage imageNamed:@"nocorrect.png"]];
[CATransaction flush];
[NSThread sleepForTimeInterval:3];
[self.navigationController popToRootViewControllerAnimated:YES];您可能需要添加Quartz框架才能正常工作,确保框架已添加到目标,并将头文件导入到ViewController.m文件中。即:
#import <QuartzCore/QuartzCore.h>https://stackoverflow.com/questions/12457529
复制相似问题