How to change view on button click in iPhone without navigation controller?

后端 未结 5 1753
小蘑菇
小蘑菇 2021-01-03 11:54

I want to know how to change view on button click in iPhone without navigation controller?

5条回答
  •  Happy的楠姐
    2021-01-03 12:18

    There are many different ways you can do that, and you should possibly provide more information about your app.

    A generic way to do it is the following, with animation:

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];    
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    
    [vc1 viewWillDisappear:YES];
    [vc2 viewWillAppear:YES];
    vc1.view.hidden = YES;
    vc2.view.hidden = NO;
    [vc1 viewDidDisappear:YES];
    [vc2 viewDidAppear:YES];
    
    [UIView commitAnimations];
    

    In this case, both views are there, you only hide/show them as you need. Alternatively, you could add/remove the view from their superview:

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];    
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    
    [vc1 viewWillDisappear:YES];
    [vc2 viewWillAppear:YES];
    [vc1 removeFromSuperview];
    [masterController.view addSubview:vc2.view;
    [vc1 viewDidDisappear:YES];
    [vc2 viewDidAppear:YES];
    
    [UIView commitAnimations];
    

提交回复
热议问题