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

发布于 2024-09-30 00:36:44 字数 1514 浏览 1 评论 0原文

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

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:0 是一个工具栏):

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等往事风中吹 2024-10-07 00:36:44

您使用了错误的选项。使用此方法,您应该使用 常量 UIViewAnimationOptionTransitionFlipFromLeft…Right 代替。

旧常量 UIViewAnimationTransitionFlipFromLeft...Right 只能用于非基于块的方法 +setAnimationTransition:...。这些常数的值分别为 1 和 2,而我上面提到的常数的值为 1 << 20和2《 20个,完全不同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文