小编Rob*_*Rob的帖子

在开始动画之前修改iPhone动画容器视图

我正在为我正在制作的纸牌游戏添加一些基本动画.(我的第一个iPhone应用程序.)

我正在创建一个自定义的UIView类"AnimationContainer",它从image1翻转到image2,同时从rect1移动到rect2.我的最终目的是让这些容器中最多有四个同时进行转换.

我遇到的问题是动画没有显示image1 ...因此只显示翻转过渡的后半部分.

但是,如果我首先通过触摸重置重置动画,那么一切都很完美.换句话说,如果我反复按Flip,我只能获得一半的转换......但是如果我先按下Reset,那么一切都可以完美地完成一次翻转.

那么,我怎样才能使动画正确重置?

下面是代码,截图,这里是完整的链接:Project Zip File 700k.

alt text http://www.robsteward.com/cardflip.jpg

- (void)displayWithImage1 {     //RESET button calls this
    self.frame = rect1;
    [image2 removeFromSuperview];
    [self addSubview:image1];
    [self setNeedsDisplay]; //no help: doesn't force an update before animation
}

- (void)runTheAnimation {     //FLIP button calls this
    [self displayWithImage1]; //<---this is what the reset button calls
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:transition forView:self cache:NO];
    self.frame = rect2;
    [image1 removeFromSuperview];
    [self addSubview:image2];
    [UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

iphone animation cocoa-touch objective-c uikit

5
推荐指数
1
解决办法
4727
查看次数

标签 统计

animation ×1

cocoa-touch ×1

iphone ×1

objective-c ×1

uikit ×1