【发布时间】:2014-02-19 19:08:14
【问题描述】:
我有一个名为 platform1、platform2、platform3 等的 UIImageView。我有一个名为 platformNumber 的 int 从一种方法(方法 1)进入另一种方法(方法 2)。
方法2(内容对我的问题没有用):
CGPoint origin = platform1.center;
CGPoint target = CGPointMake(platform1.center.x, platform1.center.y+10);
CABasicAnimation *bounce = [CABasicAnimation animationWithKeyPath:@"position.y"];
bounce.duration = 0.1;
bounce.fromValue = [NSNumber numberWithInt:origin.y];
bounce.toValue = [NSNumber numberWithInt:target.y];
bounce.repeatCount = 1;
bounce.autoreverses = YES;
[platform1.layer addAnimation:bounce forKey:@"position"];
如何更改它,以便无论在哪里出现platform1.center.x,它都会根据传递的platformNumber 值更改为platform[platformNumber]?
谢谢,任何帮助将不胜感激!
【问题讨论】:
-
如果它们是对象的属性,则使用
valueForKey,或者在开头进行切换:UIView*aPlateform; switch(thePlaftormNumber){case 1:aPlateform=plaform1;break;etc.}
标签: iphone variables methods int