0

我想使用动画翻转和展开按钮

代码:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mybutton cache:YES];
[mybutton setFrame:CGRectMake(mybutton.frame.origin.x, mybutton.frame.origin.x, 200, 200)];
[UIView commitAnimations];

此动画存在问题:
- 按钮在翻转,但在进行半圆形翻转后它正在扩展。
- 翻转后按钮位置不准确。

我该如何解决?

4

2 回答 2

0

尝试完全注释掉 setFrame,它应该会更好地翻转。还可以尝试将缓存设置为 NO。根据文档,您不应该修改在动画本身期间正在转换的视图 - cache:NO 会有所帮助,但它仍然不正确。

你通常有一个给 setAnimationTransition 函数的父视图,然后在你把旧子视图从子视图中删除之后,然后添加新子视图。这会产生一个子视图被翻转到后面而新的子视图被翻转为焦点的错觉。尽管包含孩子,但转换发生在父母身上。

无论哪种方式,请尝试将 setFrame 注释一分钟,它应该看起来更一致。

于 2011-08-21T07:01:15.443 回答
0

由于它们都是单独的动画,因此您也可以尝试使用 AnimationDidStopSelector ,一旦动画完成就会被调用;)

哦,顺便说一句,在您的 CGRectMake 中,您再次使用 x 坐标作为 y 坐标,这可能是位置不准确的原因^^

所以是这样的:

- (void)yourFunction {
    [UIView beginAnimations:nil context:indexPath];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(functionEnded:finished:context:)];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mybutton cache:YES];
    [UIView commitAnimations];
}

- (void)functionEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
        [UIView beginAnimations:nil context:indexPath];
        [UIView setAnimationDuration:1.3];
        [mybutton setFrame:CGRectMake(mybutton.frame.origin.x, mybutton.frame.origin.y, 200, 200)];
        [UIView commitAnimations];
}
于 2011-08-21T07:24:54.160 回答