簡體   English   中英

UIView動畫出現問題-一次執行同一動畫不起作用

[英]Trouble with UIView Animations - performing the same animation more than once doesn't work

我需要翻轉卡片,然后再翻轉回去。 我已經編寫了代碼來毫無困難地做到這一點。 麻煩來了,因為用戶可以根據需要來回翻轉此卡多次,而且效果似乎是累積的。 第二次嘗試時,卡片旋轉得像陀螺一樣。 我並不完全驚訝,因為似乎只有一種添加動畫的方法,而不能從視圖中清除動畫。 有沒有一種方法可以“重置”我以前提交的任何動畫的UIView? 有沒有一種方法可以捕獲它並重新使用它而無需提交新的? 還是我缺少明顯的東西? 這是我的代碼:

if (self.flipped) {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                           forView:self
                             cache:YES];
    [imageView removeFromSuperview];
    [UIView commitAnimations];
    self.flipped = NO;
} else {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:self
                             cache:YES];
    [self addSubview:imageView];
    [UIView commitAnimations];
    self.flipped = YES;
}

謝謝閱讀。

要取消所有正在進行的動畫:

#import <QuartzCore/QuartzCore.h>

...

[view.layer removeAllAnimations];

要啟動一個新動畫以殺死現有動畫(如果有的話),並從當前視圖所在的位置開始移動,我想這就是您想要的:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];

... and the rest of it ...

[UIView commitAnimations];

希望其中之一可以解決您的問題。

無論您的“自我”是什么,都將其放在一個名為foo的包含視圖中,然后將setAnimation ...行更改為此:

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                       forView:foo
                         cache:YES];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM