Wednesday 5 February 2014

Flipping Views inside a View controller

- (IBAction)flipViews:(UIButton *)sender {


    if ([self.view.subviews indexOfObject:view2]>[self.view.subviews indexOfObject:view1]) {

        [UIView transitionWithView:view1
                      duration:1
                       options:UIViewAnimationOptionTransitionFlipFromRight
                    animations:^{
                       [self.view exchangeSubviewAtIndex:[self.view.subviews indexOfObject:view1] withSubviewAtIndex:[self.view.subviews indexOfObject:view2]];
                    } completion:^(BOOL finished) {

                    }];
    }else{

        [UIView transitionWithView:view2
                          duration:1
                           options:UIViewAnimationOptionTransitionFlipFromRight
                        animations:^{
                            [self.view exchangeSubviewAtIndex:[self.view.subviews indexOfObject:view2] withSubviewAtIndex:[self.view.subviews indexOfObject:view1]];
                        } completion:^(BOOL finished) {

                        }];
    }


}
Sample Code

No comments:

Post a Comment