iphone - 在图像 1、2、3(而不是图像 1,3)之间翻转(iPhone SDK)

标签 iphone core-animation uiimageview

我正在使用一些非常标准的代码来翻转小 View 内的 2 个 UIImageView。 (我很惊讶它竟然有效!)

但是如果我在一个小 View 中有 三个 UIImageViews...并且想要在所有 3 个之间翻转怎么办?

我以为我可以剪切/粘贴我的代码的 2 个副本...但我想不行。
当我尝试翻转 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];

最佳答案

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

- (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];

有关更多信息,请查看apple docs

关于iphone - 在图像 1、2、3(而不是图像 1,3)之间翻转(iPhone SDK),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2249688/

相关文章:

iphone - 在 iPhone 的 UIPickerView 中将 UITextField 的文本设置为默认值。?

ios - 有什么方法可以在不使用 IDFA 的情况下为设备生成唯一 ID?

iphone - Cocos2D CCNode 在绝对屏幕坐标中的位置

iphone - ios 动画 Objective-C

ios - 将 ViewController 缩小为圆形过渡 - swift

ios - UIView的addMotionEffect : loses it's effect when on UICollectionViewCell

html - 将 HTML 内容转换为图像

ios - Xcode 6.1.1 为通用构建启动图像

Android:如何使用现有的图形元素

iOS 7 :How to show images from photo album without strectch while placing it in uiimageview in larger size