当应用程序启动时,我正在以编程方式创建许多具有透明背景颜色的复杂 UIView,每个都是应用程序中的“屏幕”(必须这样,因为下面有动画背景)。这会导致应用在静态启动图像上停留很长时间(大约 4 秒)。
我想在显示动画时创建所有 UIView。我无法在后台线程上创建 UIView。我怎样才能做到这一点?
尝试1:
-(void)viewDidLoad {
[super viewDidLoad];
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 200, 100)];
[baseView setBackgroundColor:[UIColor blueColor]];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 10, 180, 80)];
[button setBackgroundColor:[UIColor redColor]];
[button setTitle:@"button" forState:UIControlStateNormal]; //doesn't work
[baseView addSubview:button];
dispatch_async( dispatch_get_main_queue(), ^{ //Finished
[self.view addSubview:baseView];
});
});
}
添加了按钮,但从未设置标题。点击后出现。