Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在图像1、2、3之间切换,而不是图像1、3(iPhone SDK)_Iphone_Core Animation_Uiimageview - Fatal编程技术网

在图像1、2、3之间切换,而不是图像1、3(iPhone SDK)

在图像1、2、3之间切换,而不是图像1、3(iPhone SDK),iphone,core-animation,uiimageview,Iphone,Core Animation,Uiimageview,我正在使用一些非常标准的代码来翻转小视图中的2个UIImageView。 (我很惊讶它能起作用!) 但是如果我在一个小视图中有三个视图呢。。。想在这三个之间切换 我想我可以剪切/粘贴两份我的代码。。。但我想不会。 当我尝试翻转1>2。。然后2>3。。。它只翻转一次。。。直接从1>3开始。 2号怎么了 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; [UIView setAnimatio

我正在使用一些非常标准的代码来翻转小视图中的2个UIImageView。 (我很惊讶它能起作用!)

但是如果我在一个小视图中有三个视图呢。。。想在这三个之间切换

我想我可以剪切/粘贴两份我的代码。。。但我想不会。
当我尝试翻转1>2。。然后2>3。。。它只翻转一次。。。直接从1>3开始。 2号怎么了

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
[image1 removeFromSuperview];    
[myView addSubview:image2];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
[image2 removeFromSuperview];    
[myView addSubview:image3]; 
[UIView commitAnimations];

可以在第二个动画开始时设置0.5秒的延迟


此外,您可能希望签出关键帧动画以执行更高级的类似操作。

动画不会像这样链接在一起。基本上,他们同时制作两个动画。您需要为第二个翻转创建一个新方法,该方法将在第一个翻转完成后调用:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)contextn {
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
    [image2 removeFromSuperview];    
    [myView addSubview:image3]; 
    [UIView commitAnimations];
}
然后在您现有的方法中,将这一行:

[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
像这样:

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[image1 removeFromSuperview];    
[myView addSubview:image2];
[UIView commitAnimations];
有关更多信息,请查看吉尔

在第二个代码块中,执行以下操作

[UIView beginAnimations:nil context:NULL];

// This will cause your second animation block to wait 0.5 second, which will be 
// enough time for the second one to kick in and do it's thing.
[UIView setAnimationDelay:0.5];

[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
[image2 removeFromSuperview];    
[myView addSubview:image3]; 
[UIView commitAnimations];

哇!好啊我试试看。但我认为“承诺”是“现在就做”的全部意义。。。与其说“现在不要做……等我运行另一个翻转……然后取消上一个翻转……完全没有警告”。>更多信息,请查看我已经阅读了数千页iPhone文档的苹果文档。。。我能忍受的。我仍然错过了关于“commitAnimations现在没有真正制作动画”的部分。@commitAnimations 1-它没有取消它,它们是同时发生的@评论2-iPhone默认为单线程。在方法仍在运行时,使其工作的唯一方法是让这些方法在后台运行并调用performSelectorOnMainThread(因为所有UI都必须在主线程上)。但即便如此,动画也只会比以前提前一纳秒启动。CommitAnimations不是同步调用…这意味着您的应用程序不会在这两个动画之间暂停。