【问题标题】:UIView animation block not animation view's subviewsUIView 动画块不是动画视图的子视图
【发布时间】:2010-10-29 19:14:30
【问题描述】:

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

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
         ];
}

视图实际上是交换的,只是没有任何动画。这很奇怪。我还尝试将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
         ];
}

【问题讨论】:

    标签: ios uiviewanimation uiviewanimationtransition


    【解决方案1】:

    您使用了错误的选项。使用此方法,您应该改用the constants UIViewAnimation<b>Option</b>TransitionFlipFromLeft and …Right

    旧常量UIViewAnimationTransitionFlipFromLeft…Right 应该只用于非基于块的方法+setAnimationTransition:…。这两个常量的值分别是 1 和 2,而我上面提到的那些值是 1

    【讨论】:

    • 非常感谢!我猜这是 Xcode 中的一个错误,它在编译时不建议甚至不识别此选项(尽管它编译时没有错误,只是不会将文本颜色更改为“OK”编译选项)。
    • @Canada:这不是 Xcode 中的错误,而是 C 标准 (gcc) 不会阻止不同 enums 的常量混淆。
    • 是的,对不起,我看了更多的类,只是看到了编译器的东西。谢谢:)
    • @Canada 你没有收到编译器警告的原因是因为它是一个枚举,当你把它归结为它的本质时,它只是一个整数。这意味着传入不带“Option”的值是完全有效的,因为它的值也是一个整数。
    • 完全被这个卡住了,谢谢你的好眼球:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多