通常我不会在viewDidLoad
中执行任何动画。
但出于测试目的,我尝试在viewDidLoad
中逐个放置并测试这些:
CABasicAnimation
[UIView animateWithDuration:delay:options:animations:completion:]
最后现在弃用了:
[UIView BeginAnimation]
(我很长一段时间没用过;再次,在这种情况下只是为了测试目的)
我经历过一些我过去几个小时无法解释的事情。
在viewDidLoad
中,如果我启动CABasicAnimation
,它可以正常运行。
但如果我放置:
[UIView animateWithDuration:delay:options:animations:completion:]
中的 [UIView BeginAnimation]
或viewDidLoad
,不会启动动画,而是将项目放置在最终的动画位置。
出于好奇,我做了以下事情:
我将[UIView animateWithDuration:delay:options:animations:completion:]
或[UIView BeginAnimation]
包裹在:
double delayInSeconds = 0.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void)
{
//UIView animation block / [CAAnimation Begin] Animation goes here. As you can see,
//there is no delay here.
//I did this out of hunches.
});
再次在viewDidLoad
中,然后动画发生。这不是因为dispatch_get_main_queue()
我认为是因为我尝试使用以下内容在dispatch_after
之前记录队列:
NSLog(@"%@", [NSOperationQueue mainQueue]);
实际上它在主队列上(事实上,我根本没有使用任何GCD
。但是为了确认,我试图以这种方式记录它。
任何人都可以向我解释为什么 CABasicAnimation
在这里工作viewDidLoad
而其他人没有。为什么即使没有延迟,UIView animation
阻止[CAAnimation Begin]
阻止dispatch_after
也会有效?
我只是测试这些类型的动画方法(这是我的目标);所以我没有做复杂的动画 - 只是简单地将项目从一个点线性移动到另一个点。