문제

I have a project in which I'm switching one view with another:

- (IBAction)onClick:(id)sender
{
ViewControllerSecond * sc=[[ViewControllerSecond alloc]initWithNibName:@"ViewControllerSecond" bundle:nil];
[UIView transitionFromView:self.view toView:sc.view duration:3.0
                   options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {

}];
}

I'm using 3 seconds here to make a point. in this second view I have a method to update the GUI that adds another view from a view controller:

    -(void)updateGUI
{

    sample=[[ViewControllerSample alloc]initWithNibName:@"ViewControllerSample" bundle:nil];
    sample.view.frame=CGRectOffset(sample.view.frame, 0, 150);
    [self.view addSubview:sample.view];
}

Now, here is the problem: when I'm calling this from the viewDidLoad function - it's working just fine. However, if called from the viewWillAppear function, the view will appear at the top of the screen and only after the animation has ended will jump to it's position. How can it be fixed?

도움이 되었습니까?

해결책 3

The answer for that was of two parts:

  1. update when the view is loaded, however this will only happen once, so to re-use the controller I have to call it again.
  2. use the isViewLoaded to see if the view is loaded. if it is, then call the update method.

다른 팁

Whats wrong putting it in viewDidLoad?

From the looks of it, the order is loading, animating then the delegate methods of appearing. Also put your sample=[[ViewControllerSample alloc]initWithNibName:@"ViewControllerSample" bundle:nil]; in the init part of your Second view controller.

Alternatively, you can call updateGUI before your animation. So before [UIView transition...

[sc updateGUI];

Just call updateGUI in viewDidLoad. Don't do much work in viewWillAppear. viewWillAppear will prevent your view's appear if you make it do too much work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top