到目前为止,在UIViewAnimation
中,我使用了一个图像从一个地方到另一个地方的动画,如下所示:
CGRect frame = button.frame;
CGRect frame1 = button1.frame;
frame.origin.x = frame1.origin.x;
frame.origin.y = frame1.origin.y;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView animateWithDuration:3.0 animations:^{
[button setTransform:CGAffineTransformIdentity];
} completion:^(BOOL finished) {
}];
button.frame = frame;
[UIView commitAnimations];
这里我有九个阵列中的图像:
redAppleArray = @[redApple1,redApple2,redApple3,redApple4,redApple5,redApple6,redApple7,redApple8,redApple9,redApple10];
我有文本显示随机数字。
我的问题是如何获得上述文本值并使用UIViewAnimation
对图像进行动画处理?即,如果text =3
、3 redApple
被动画化。
例如,要从标签中获取值,请执行以下操作:
int i = [[myLabel text] intValue];
然后使用它来获取数组中的元素:
id *redApple = [redAppleArray objectAtIndex:i];
尝试做一些轻松的事情:
-(void)yourMethodToAnimateWithText:(NSString*)numberAsAText {
int = [numberAsAText intValue];
CGRect frame = button.frame;
CGRect frame1 = button1.frame;
frame.origin.x = frame1.origin.x;
frame.origin.y = frame1.origin.y;
// If you want to add some option use [UIView animateWithDuration:delay:option:animation:completion:]
[UIView animateWithDuration:3.0 animations:^{
//[button setTransform:CGAffineTransformIdentity];
button.frame = frame;
//Animate your images, text, etc.
} completion:^(BOOL finished) {
}];
}
希望这就是你追求的。