1

i have an animation that works in the main menu screen of an iPad application. when select some menu item, the application will push the new view the navigation controller. the problem happens when i want to restart the animation again in the moment of when i push the back button and return to the main menu again.

i tried to put the animation code in these methods :

-(void) viewDidLoad  

-(void) viewDidAppear

but i can't get them to work.

what i am trying to do is animation the company's logo in the background .

my code is :

[UIView beginAnimations:nil context:NULL];    
[UIView setAnimationDuration:15.0];
[UIView setAnimationRepeatCount:20.0f];
[UIView setAnimationRepeatAutoreverses:YES];

CGPoint pos = large_bright.center; 
pos.x = 400.0f;
large_bright.center = pos;
CGPoint pos2 = large_dim.center; 
pos2.x = -10.0;
large_dim.center = pos2;
[UIView commitAnimations];
adel
  • 127
  • 1
  • 13
  • Show some code what you have tried. The question is not accurate to understand, Please clarify it clearly – Sumanth Jul 09 '12 at 12:49
  • I am assuming that your menu is a full screen view with its own view controller? What animation are you trying to perform on what objects? Are you simply trying to animate the menu view out of the way, or animate subviews that are within the non-menu main view? We need more info to better help you out! – trumpetlicks Jul 09 '12 at 12:58
  • i am trying to animate some of the company's logos in the background. the code is in the question now. – adel Jul 09 '12 at 13:15
  • Please try to put repeatcount to 0 and try to cancel the animation on the viewWillDisappear method it is possible with some code but dont know exactly. – The iOSDev Jul 09 '12 at 13:31
  • i tried but i could not do it .. – adel Jul 09 '12 at 14:50

3 Answers3

0

Try:

[UIView animateWithDuration:1.0 // set here how fast u want it to animate
                 animations:^{ 
                     // add your needed animation here

                 } 
                 completion:^(BOOL finished) {  
                     // do some stuff when its done if you need to
                 }    
 ];
Norbert Bicsi
  • 1,562
  • 2
  • 19
  • 33
0

you should call

  • (void)viewWillAppear:(BOOL)animated;
sanjeev sharma
  • 313
  • 2
  • 9
-1

Call some other function from viewDidLoad and viewDidAppear.and then add your animation code in that function.

-(void) viewDidLoad
{
   [self add_animation];
}
-(void)animation
{
   //your animation code
}
Madhumitha
  • 3,794
  • 8
  • 30
  • 45
  • 1
    Actually , you should never do animations until the view appeared. So the earliest time in a view controller's life cycle when you can do animations is viewDidAppear. Otherwise you will get a wait for fences warning . Which is there for a reason. – George Jul 09 '12 at 13:00
  • @George Sorry I cannot understand.Please explain. – Madhumitha Jul 09 '12 at 13:08
  • Let's say you are doing animations on a view called V . That view belongs to a view controller called MyViewController. If MyViewController is not fully displayed currently ( aka viewDidAppear was not called yet ) , the fact that you are trying to perform an animation will throw an warning. Check this out: http://stackoverflow.com/questions/1371346/wait-fences-failed-to-receive-reply-10004003 – George Jul 09 '12 at 13:11