Normally I don't perform any animation in viewDidLoad
.
But for testing purposes, I tried to place and test these one by one within viewDidLoad
:
CABasicAnimation
[UIView animateWithDuration:delay:options:animations:completion:]
and finally the now deprecated:
[UIView BeginAnimation]
(which I haven't used for a long time; again, just for testing purpose in this case)
And I experienced some thing I cannot explain for the past hours.
In viewDidLoad
, if I start the CABasicAnimation
, it works - it animates.
But if I place either:
[UIView animateWithDuration:delay:options:animations:completion:]
or [UIView BeginAnimation]
in viewDidLoad
, no animation is started and instead the item will be placed at the final animated position.
Out of curiosity, I did the following:
I wrapped either [UIView animateWithDuration:delay:options:animations:completion:]
or[UIView BeginAnimation]
within:
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.
});
again in viewDidLoad
, then animation happens. It is not because of dispatch_get_main_queue()
I think because I tried to log the queue before dispatch_after
above by using:
NSLog(@"%@", [NSOperationQueue mainQueue]);
It is in fact on the main queue (as a matter of fact, I am not using any GCD
at all. But just to confirm, I tried to log it this way.
Can anyone explain to me why CABasicAnimation
works here in viewDidLoad
and others don't. And why placing UIView animation
block and the [CAAnimation Begin]
within dispatch_after
even without delay works?
I am just testing these types of animation methods (that is my goal); so I am not doing complex animation - it is just something as simple as moving an item linearly from one point to another.