Ios UIView转换FromView

Ios UIView转换FromView,ios,uiview,uiviewanimationtransition,Ios,Uiview,Uiviewanimationtransition,我对iOs编程相当陌生。我陷入了一个(我肯定)非常简单的问题。 不知道我做错了什么 -我的视图加载: [super viewDidLoad]; CGRect frame = CGRectMake(0, 0, 768, 1024); UIView *uno=[[[UIView alloc] initWithFrame:frame] autorelease]; UIImageView *mainView = [[[UIImageView alloc] initWithFrame:frame] au

我对iOs编程相当陌生。我陷入了一个(我肯定)非常简单的问题。 不知道我做错了什么

-我的视图加载:

[super viewDidLoad];

CGRect frame = CGRectMake(0, 0, 768, 1024);
UIView *uno=[[[UIView alloc] initWithFrame:frame] autorelease];
UIImageView *mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
mainView.image = [UIImage imageNamed:@"photo.jpg"];
[uno addSubview:mainView];

UIView *dos=[[[UIView alloc] initWithFrame:frame] autorelease];
UIImageView *mainViewDos = [[[UIImageView alloc] initWithFrame:frame] autorelease];
mainViewDos.image = [UIImage imageNamed:@"Default.png"];
[dos addSubview:mainViewDos];
//
[self.view addSubview:uno];
//
[self anima:uno:dos];
NSDictionary *views = [NSDictionary dictionaryWithObjectsAndKeys:uno, @"uno", dos, @"dos", nil];
[self performSelector:@selector(anima) withObject:views afterDelay:0.1];
我的阿尼玛方法:

-(void) anima:(UIView *)uno:(UIView *)dos{
    [UIView transitionFromView:uno
                        toView:dos
                      duration:2.0
                       options:UIViewAnimationOptionTransitionFlipFromLeft
                    completion:nil];
}
它改变了视图,但没有转换


谢谢

您不能在viewDidLoad中执行动画--您在viewDidLoad中所做的视图更改都是在视图实际显示之前执行的,这就是您所看到的

首次显示视图时是否尝试显示此动画?如果是这样,可以通过将动画置于计时器上使其工作。注意,使用这种方法,您还必须稍微重构
anima
方法,以获取单个参数

在您的viewDidLoad中:

[super viewDidLoad];

CGRect frame = CGRectMake(0, 0, 768, 1024);
UIView *uno=[[[UIView alloc] initWithFrame:frame] autorelease];
UIImageView *mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
mainView.image = [UIImage imageNamed:@"photo.jpg"];
[uno addSubview:mainView];

UIView *dos=[[[UIView alloc] initWithFrame:frame] autorelease];
UIImageView *mainViewDos = [[[UIImageView alloc] initWithFrame:frame] autorelease];
mainViewDos.image = [UIImage imageNamed:@"Default.png"];
[dos addSubview:mainViewDos];
//
[self.view addSubview:uno];
//
[self anima:uno:dos];
NSDictionary *views = [NSDictionary dictionaryWithObjectsAndKeys:uno, @"uno", dos, @"dos", nil];
[self performSelector:@selector(anima) withObject:views afterDelay:0.1];
然后将
anima
方法更改为:

-(void) anima:(NSDictionary *)views {
  [UIView transitionFromView:[views objectForKey:@"uno"]
                      toView:[views objectForKey:@"dos"]
                    duration:2.0
                     options:UIViewAnimationOptionTransitionFlipFromLeft
                  completion:nil];
}