-1

I am having a problem in an animation of a view.
Firstly, I made an animation within ViewDidLoad method. It works perfectly.
Then within the view, I need to call out another view from the storyboard by storyboard ID using the below method

UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    myprofile *obj = [story instantiateViewControllerWithIdentifier:@"myprofile"];
    [self presentViewController:obj animated:YES completion:nil];

This view is just use for preferences and setting. After the setting is done, I called

[self dismissViewControllerAnimated:YES completion:nil];

The problem came when it dismissed. It can go back into the viewDidload before, but the animation started again.

My question is, is there anyway I can skip the animation that I called in viewDidload when I dismiss my second view?

Many Thanks

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
Clarence
  • 1,951
  • 2
  • 34
  • 49

3 Answers3

1

Maybe you can create a class which inherit of UIViewController with a attribute like var playing : Bool = true and change it before dismiss you view controller.

Florian
  • 855
  • 7
  • 12
1

Since you re-create your controller each time before displaying it, you need to store a flag somewhere. Roughly speaking the quick hack would be to use dispatch_once on your animation. But you may decide to store a flag in parent controller and manually start animation from parent controller. There are really million ways to organize it.

pronebird
  • 12,068
  • 5
  • 54
  • 82
1

You can use add/post local notification for this.Manage a bool variable with YES for a go animation and NO for no animation. Add observer in the viewdidLoad before calling the animation.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(SettingsDone) name:@"AnimationDone" object:nil];
if (goAnimate){
  UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
 myprofile *obj = [story instantiateViewControllerWithIdentifier:@"myprofile"];
 [self presentViewController:obj animated:YES completion:nil];
}

-(void)SettingsDone{ goAnimate=NO; }

You can post a local notification to parent class before dismissing the pop up view.

[NSNotificationCenter defaultCenter]postNotificationName:@"AnimationDone" object:nil userInfo:nil];
[self dismissViewControllerAnimated:YES completion:nil];
NewStackUser
  • 657
  • 5
  • 17