Xcode 无法识别 UIViewAnimationOptionTransitionFlipFromRight

发布于 2024-10-12 00:00:38 字数 1532 浏览 6 评论 0原文

我正在实现一个非常简单的翻转动画,但翻转不存在。

我使用文档中的示例作为模板,Apple 现在建议您使用动画块,这是要采取的方法:(来自文档)

[UIView transitionWithView:containerView
           duration:0.2
           options:UIViewAnimationOptionTransitionFlipFromLeft
           animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; }
           completion:NULL]; 

将要在容器中转换的两个视图包装起来。 我就是这样做的。

UIView *container = [[UIView alloc] initWithFrame:target];
[self.view addSubview:container];
[container addSubview:productImage];

UIView *background = [[UIView alloc] initWithFrame:target];
[background setBackgroundColor:[UIColor darkGrayColor]];
[background setAlpha:0.1f];

[UIView transitionWithView:container
                  duration:0.8
                   options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{ 
                    [[[container subviews] objectAtIndex:0] removeFromSuperview];
                    [container addSubview:background]; 
                }
                completion:NULL];

发生了两件奇怪的事情: 没有过渡,容器显示productImage(类型为UIImageView),然后将其与背景视图交换。没有动画。

第二件事让我相信这不是常见的拼写错误,而是

UIViewAnimationOptionTransitionFlipFromRight

Xcode 无法识别,它不会自动完成,也不会突出显示。仅当我使用已弃用的版本时,Xcode 才会执行此操作:

UIViewAnimationTransitionFlipFromRight //i.e. without the Option part

然后我开始检查我的 SDK 版本等。所有内容似乎都设置为 4.2,XCode 版本为 3.2.5,目标和项目设置都将构建和部署目标设置为 4.2。

我在这里缺少什么?

希望训练有素的眼睛可以帮助我:) 提前谢谢你。

I am implementing a very simple flip animation, but the flip isn't there.

I am using an example from the docs as a template, Apple now recommends you use blocks for animations and that this is the approach to take: (from the docs)

[UIView transitionWithView:containerView
           duration:0.2
           options:UIViewAnimationOptionTransitionFlipFromLeft
           animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; }
           completion:NULL]; 

Wrapping the two views you want to transition between in a container.
I do it like this.

UIView *container = [[UIView alloc] initWithFrame:target];
[self.view addSubview:container];
[container addSubview:productImage];

UIView *background = [[UIView alloc] initWithFrame:target];
[background setBackgroundColor:[UIColor darkGrayColor]];
[background setAlpha:0.1f];

[UIView transitionWithView:container
                  duration:0.8
                   options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{ 
                    [[[container subviews] objectAtIndex:0] removeFromSuperview];
                    [container addSubview:background]; 
                }
                completion:NULL];

Two strange things happen:
There is no transition, the container displays the productImage (of type UIImageView), then swaps it with the background view. No animation.

The second thing is what led me to believe that this is not the usual typo, was that the

UIViewAnimationOptionTransitionFlipFromRight

is not recognized by Xcode, it will not autocomplete, it is not highlighted. Xcode will only do that if I use the deprecated:

UIViewAnimationTransitionFlipFromRight //i.e. without the Option part

I then started to check my SDK version etc. everything seems to be set to 4.2, XCode is version 3.2.5, both target and project settings has build and deploy target set to 4.2.

What am I missing here?

Hope a set of trained eyes can help me:) thank you in advance.

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

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

发布评论

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

评论(2

深海蓝天 2024-10-19 00:00:39

这段代码可以帮助你

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];


UIViewAnimationTransition transition = UIViewAnimationTransitionFlipFromRight;
[UIView setAnimationTransition:transition forView:[self.navigationController view] cache:NO];


[UIView commitAnimations];

干杯

This code will help you

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];


UIViewAnimationTransition transition = UIViewAnimationTransitionFlipFromRight;
[UIView setAnimationTransition:transition forView:[self.navigationController view] cache:NO];


[UIView commitAnimations];

Cheers

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