iphone – 如何在viewDidAppear中向UIView添加动画?
发布时间:2020-12-14 19:58:36 所属栏目:百科 来源:网络整理
导读:我试图向viewDidLoad和viewDidAppear添加动画,但它不起作用: - (void)viewDidAppear:(BOOL)animated{ [UIView beginAnimations:@"transition" context:NULL]; [UIView setAnimationTransition:110 forView:self.view cache:YES]; [UIView commitAnimations]
我试图向viewDidLoad和viewDidAppear添加动画,但它不起作用:
- (void)viewDidAppear:(BOOL)animated{ [UIView beginAnimations:@"transition" context:NULL]; [UIView setAnimationTransition:110 forView:self.view cache:YES]; [UIView commitAnimations]; } 为什么? 解决方法
我有同样的问题,我想我找到了这个
SO question的解决方案.
当调用viewDidAppear时,你仍然看不到屏幕上的任何内容(尽管有名字),但是你即将到来.然后,您可以使用performSelector:withDelay或NSTimer来启动动画.延迟可以为0.1,您的动画将在屏幕出现时播放. - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"View did appear!"); [self performSelector:@selector(animationCode) withObject:nil afterDelay:0.1f]; } - (void)animationCode { // you animation code } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容