Cocoa touch - UIAnimation question
Hey guys, I still haven't found an answer to this so I think I'll ask you.
[viewOggetto setFrame:aFrame];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[viewOggetto.view setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:viewOggetto.view];
[UIView commitAnimations];
this is a simple animation for a view to appear in a positi开发者_Go百科on and then go full screen. My question is: how can I make the content of the view follow the animation as well? Now I have the view frame animating correctly but everything that is inside the view just appears fullscreen instantly.
Thanks.
It's not entirely clear what you want to happen instead of it appearing full-screen instantly. You mean you want it to fade in? Set the alpha
property on the subview to 0
and add it to self.view
before you start the animation. Then set the alpha
property to 1 within the animation.
but what viewOggetto exactly is? if it's a UIView then why to call viewOggetto.view?
is it a UIViewController? You call both :
[viewOggetto setFrame:aFrame];
[viewOggetto.view setFrame:aFrame];
assuming it's a UIViewController, try this / prova cosi':
[self.view addSubview:viewOggetto.view]; // you need to have it before to animate it
// initial state of the animation:
[viewOggetto.view setFrame:CGRectMake(160, 240, 1, 1)]; // zoom from center
// viewOggetto.view.alpha = 0; // eventually to add a fadeIn animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
// ending state of animation:
// viewOggetto.view.alpha = 1; // restore to 1 to eventually to add a fadeIn animation
[viewOggetto.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
if it's a UIView just delete ".view" in every "viewOggetto.view" code
ciao, luca
Just want to add to Jim's answer. UIView animations animate UIViews from one context to another. If the context doesn't exist before the [UIView beginAnimations:nil context:NULL];
then underside effects will happen. The context wont exist if the view hasn't been added to subview.
精彩评论