UIView动画块不是动画视图的子视图

run*_*mad 4 uiviewanimation uiviewanimationtransition ios

我无法使用以下代码实现任何动画:

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
         ];
}
Run Code Online (Sandbox Code Playgroud)

视图实际上是交换,但没有任何动画.这很奇怪.我也曾尝试交换mapViewtableViewself.view.subviews像这样(objectAtIndex:0toolBar):

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
         ];
}
Run Code Online (Sandbox Code Playgroud)

ken*_*ytm 17

您使用的是错误的选项.使用此方法,您应该使用常量而UIViewAnimationOptionTransitionFlipFromLeft…Right不是.

旧的常量UIViewAnimationTransitionFlipFromLeft…Right应仅用于非基于块的方法+setAnimationTransition:….这些常数分别具有值1和2,而我上面提到的值具有值1 << 20和2 << 20,它们完全不同.