如何在viewDidAppear中向UIView添加动画

如何在viewDidAppear中向UIView添加动画

本文介绍了如何在viewDidAppear中向UIView添加动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试向viewDidLoad和viewDidAppear添加动画,但它不起作用:

I tried to add a animation to viewDidLoad and viewDidAppear, but it doesn't work:

- (void)viewDidAppear:(BOOL)animated{
 [UIView beginAnimations:@"transition" context:NULL];
 [UIView setAnimationTransition:110 forView:self.view cache:YES];
 [UIView commitAnimations];
}

为什么?

推荐答案

我遇到了同样的问题,我想我找到了解决方案。

I had the same problem and I think I found the solution on this SO question.

当调用viewDidAppear时,你仍然看不到屏幕上的任何内容(尽管有名字) ,但你即将到来。然后,您可以使用performSelector:withDelay或NSTimer来启动动画。延迟可以只有0.1,你的动画就会在屏幕出现时播放。

When viewDidAppear gets called you still don't see anything on the screen (despite the name), but you are about to. You can then use a performSelector:withDelay or an NSTimer to launch your animation. The delay can just be 0.1 and your animation will play just when the screen appears.

- (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
}

这篇关于如何在viewDidAppear中向UIView添加动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:39