在您的问题中,您要问如何:
- 更新对象的属性
- 移动它
- 更新同一对象的属性
- 淡出
...这样当您触摸屏幕时它可以重新出现在另一个地方。
此外,你想用一种方法来做到这一点......
我建议采取不同的方法来解决这个问题。
首先,尝试将形状视为在您删除或处置它们之前一直存在的对象。基本上,您可以将对象视为将传递给各种方法的事物。
当您开始这样思考时,您可以使用以下技术来制作您正在寻找的效果:
#import "C4WorkSpace.h"
@implementation C4WorkSpace
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {
CGPoint touchPoint = [t locationInView:self.canvas];
[self createObjectAtPoint:touchPoint];
}
}
-(void)createObjectAtPoint:(CGPoint)newPoint {
C4Shape *s = [C4Shape ellipse:CGRectMake(newPoint.x-25,newPoint.y-25,50,50)];
s.userInteractionEnabled = NO;
[self.canvas addShape:s];
[self runMethod:@"fadeAndRemoveShape:" withObject:s afterDelay:0.0f];
}
-(void)fadeAndRemoveShape:(C4Shape *)shape {
shape.animationDuration = 1.0f;
shape.alpha = 0.0f;
[shape runMethod:@"removeFromSuperview" afterDelay:shape.animationDuration];
}
@end
这是做什么的:
- 获得接触点
- 将触摸点传递给创建形状的方法
- 将创建的形状传递给淡出它的方法
- 当它消失时从画布中删除形状
- 形状从屏幕上删除后会自动从内存中删除