我会尝试创建一个伪动画,当一个视图出现时。这是我的代码:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
_image1.hidden = NO;
sleep(1);
_label1.hidden = YES;
sleep(1);
_image2.hidden = NO;
sleep(1);
_label2.hidden = YES;
sleep(1);
}
但是在每次sleep()之前视图都没有更新。我必须添加什么,在显示或隐藏图像或标签后视图会更新?
答案 0 :(得分:1)
试试这个:
[_image1 performSelector:@selector(setHidden:) withObject:[NSNumber numberWithBool:true] afterDelay:1];
[_label1 performSelector:@selector(setHidden:) withObject:[NSNumber numberWithBool:false] afterDelay:2];
[_image2 performSelector:@selector(setHidden:) withObject:[NSNumber numberWithBool:true] afterDelay:3];
[_label2 performSelector:@selector(setHidden:) withObject:[NSNumber numberWithBool:false] afterDelay:4];
答案 1 :(得分:0)
您无法使用sleep
,因为它会停止您当前的主题并阻止您的应用更新显示。
我建议使用......
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5]; // you can also set this to 0.0
[UIView setAnimationDelay:1.0]; // the delay
// your changes which should be animated, example:
_image1.alpha = 0.0;
[UIView commitAnimations];
简单且可扩展。