UIViewAnimationOptionTransitionFlipFromRight无法被Xcode识别

时间:2011-01-13 12:47:21

标签: xcode ios uiviewanimationtransition

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

我使用文档中的示例作为模板,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。

我在这里缺少什么?

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

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:-1)

此代码可以帮助您

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


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


[UIView commitAnimations];

干杯