views:

22

answers:

1

I am unable to achieve any animation with the following code:

if (self.segmentControl.selectedSegmentIndex == 0) {
    [UIView transitionFromView:tableView
                        toView:mapView
                      duration:1.0
                       options:UIViewAnimationTransitionFlipFromLeft
                    completion:nil
         ];
    }
if (self.segmentControl.selectedSegmentIndex == 1) {
    [UIView transitionFromView:mapView
                        toView:tableView
                      duration:1.0
                       options:UIViewAnimationTransitionFlipFromRight
                    completion:nil
         ];
}

The views are actually swapping, but just without any animation. It's quite strange. I have also tried to swap mapView and tableView with self.view.subviews like so (objectAtIndex:0 is a toolBar):

if (self.segmentControl.selectedSegmentIndex == 0) {
    [UIView transitionFromView:[self.view.subviews objectAtIndex:1]
                        toView:[self.view.subviews objectAtIndex:2]
                      duration:1.0
                       options:UIViewAnimationTransitionFlipFromLeft
                    completion:nil
         ];
    }
if (self.segmentControl.selectedSegmentIndex == 1) {
    [UIView transitionFromView:[self.view.subviews objectAtIndex:2]
                        toView:[self.view.subviews objectAtIndex:1]
                      duration:1.0
                       options:UIViewAnimationTransitionFlipFromRight
                    completion:nil
         ];
}
A: 

You are using the wrong options. With this method, you should use the constants UIViewAnimationOptionTransitionFlipFromLeft and …Right instead.

The old constants UIViewAnimationTransitionFlipFromLeft and …Right should only be used for the non-block-based method +setAnimationTransition:…. These constants have values 1 and 2 respectively, while the ones I mentioned above have values 1 << 20 and 2 << 20, which are totally different.

KennyTM
Thanks very much! I guess it's a bug in Xcode that it doesn't suggest or even recognizes this option when compiling (although it compiles without errors, just doesn't change the text colour to a "OK" compiled option).
Canada Dev
@Canada: It's not a bug in Xcode, but that the C standard (`gcc`) don't prevent constants of different `enum`s from mixing up.
KennyTM
Yeah, sorry, I looked at the class a bit more and just saw the compiler stuff. Thanks :)
Canada Dev