1
votes

I'm doing a flipping animation between UIView and UIScrollView. Flipping animation is ok. The problem is I can't flip back and forth between the two views. Check my code. I have a BOOL variable called mapViewShowing to check current view.

My initial view is scrollview when I tap the bar button the view will flip between map view and scrollview. I can flip two times between the two views. After that the flip animation stop at map view and can't flip anymore. Both views are under the same parent view. Help me please. Thank you.

if(!mapViewShowing) {
    [UIView transitionFromView:self.scrollView
                    toView:self.mapView
                  duration:1
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                completion:^(BOOL finished) {
                    mapViewShowing = YES;
                }];
} else {
    [UIView transitionFromView:self.mapView
                        toView:self.scrollView
                      duration:1
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    completion:^(BOOL finished) {
                        mapViewShowing = NO;
                    }];
}
2
Try with adding scrollview inside a container uiview, and then use the same code. - Mrunal
still stuck after the second flip - Zune Moe

2 Answers

3
votes

This works

IN the .m file

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [container addSubview:page1];  //You need a container view should have the same size as
                                   //as the view that you will animate
    mainViewVissible=YES;

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)doFlip:(id)sender {


    [UIView transitionFromView: (mainViewVissible ? page1:page2)
                        toView: (mainViewVissible ? page2 : page1)
                      duration:0.5
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    completion:^(BOOL finished){

                        mainViewVissible=!mainViewVissible;
                        /* do something on animation completion */
                    }];




}

In the .h file

@property (weak, nonatomic) IBOutlet UIView *container;
@property (strong, nonatomic) IBOutlet UIView *page1; //I have the view in the nib
@property (strong, nonatomic) IBOutlet UIView *page2;
@property (weak, nonatomic) IBOutlet UIButton *flipBtn;

Hope that this will help

3
votes

To transition back and forth, you should add UIViewAnimationOptionShowHideTransitionViews to the options parameters to both transition animation. Your options parameters should be UIViewAnimationOptionShowHideTransitionViews | UIViewAnimationOptionTransitionFlipFromLeft