On Mar 3, 2011, at 8:16 PM, Matt Neuburg wrote:
> Except that as Robert Vojta told you (and as Luke Hiesterman has clearly
> stated on other occasions) it is wrong to assume that viewDidLoad means that
> the view is now in the *interface*, or even that it is *about* to be put into
> the interface, so it makes no sense to assume that an animation launched from
> viewDidLoad, even with delayed performance, will be seen by the user. It
> might appear to work, but it's still wrong. So this solution is incorrect:
>
>>> On Mar 2, 2011, at 12:42 PM, Andreas Grosam wrote:
>>>
>>>> - (void) viewDidLoad {
>>>> // ...
>>>> [self performSelector:@selector(addButtonWithAnimation) withObject:nil
>>>> afterDelay:0.0];
>>>> }
> The proper way to trigger an animation when the view first appears is in
> viewDidAppear:,
Matt, you are right, scheduling an action in -viewDidLoad is not the correct
method for starting animations, and I did mention this. My suggestion was
merely a quick fix to *test the animation* in the OPs *sample*.
Nonetheless, I think there is an issue with certain animations started via
transitionWithView:.. and transitionFromView:.. , please read on.
Animations can be started only if the view has a window. When a view
controller's view is loaded, it has not yet been assigned a super view, so
there's also no window, and hence the animation wont start. So, when scheduling
an animation via performSelector:withObject:afterDelay: there's no guarantee
that the window is set when the method fires.
So, after experiencing that the following UIView transition... animation
- (void) addButtonWithAnimation {
[UIView transitionWithView:self.view
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{ [self.view addSubview:self.button]; }
completion:NULL];
}
will not work when invoked in -viewWillAppear. My first guess was, because the
window - immediately after loading the view - is not yet set for the view, this
might be the cause of the problem. But no:
I looked a bit closer and -- become stumped:
I found, that even invoking the same animation in -viewDidAppear will not work
as well! (here, the window is set)
More precisely, the "curlup" animation for the container view (self.view) is
not showing. If however, the animation block has additional animations for
style properties of self.button, these will be animated. It doesn't matter
whether the button will be added in the animation block or has been added
previously.
It just happens that it worked when scheduled from the main thread via
performSelector:withObject:afterDelay:.
It also works when triggered from an action, invoked by a button tabbed by the
user.
Well, it should be noted that animations defined as:
[self.view addSubview:animatedView];
CGAffineTransform transform = ...
[UIView animateWithDuration:0.2
animations:^{
animatedView.transform = transform;
}
completion:NULL];
DO work when invoked in -viewDidAppear and -viewWillAppear.
Likewise, it doesn't matter if the animated view will be added within the
-viewDidAppear method or has been added previously.
So it seems, there is a problem performing UIViewAnimationOptionTransition...
animations for the UIView transitionWithView:... class method, and possibly for
transitionFromView:... invoked from -viewWillAppear: and viewDidAppear:.
Regards
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]