Xcode 无法识别 UIViewAnimationOptionTransitionFlipFromRight
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4680199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIViewAnimationOptionTransitionFlipFromRight not recognized by Xcode
提问by RickiG
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)
我使用文档中的一个示例作为模板,Apple 现在建议您使用块来制作动画,这是采用的方法:(来自文档)
[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.
发生了两件奇怪的事情:没有过渡,容器显示 productImage(UIImageView 类型),然后将其与背景视图交换。没有动画。
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:
Xcode 无法识别,它不会自动完成,也不会突出显示。如果我使用已弃用的,Xcode 只会这样做:
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.
然后我开始检查我的 SDK 版本等。一切似乎都设置为 4.2,XCode 是版本 3.2.5,目标和项目设置都将构建和部署目标设置为 4.2。
What am I missing here?
我在这里错过了什么?
Hope a set of trained eyes can help me:) thank you in advance.
希望一组训练有素的眼睛可以帮助我:) 在此先感谢您。
回答by ff10
If you are going with blocks (and everyone should start going with them), please refer to
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion
如果你正在使用块(每个人都应该开始使用它们),请参考
+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion :(void (^)(BOOL 完成))完成
and/or
和/或
回答by Aditya
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
干杯