2

我想做

  1. 将动画持续时间更改为 0
  2. 做一点事
  3. 将 animationDuration 更改为更长的时间(例如 1.0f)
  4. 做别的事

...全部在 touchesBegan 方法中,中间没有任何“暂停”。但似乎它不会让我这样做。

像这样:

s1.animationDuration = 0.0f;
s1.center = touchedPoint;
s1.alpha = 1.0f;
s1.animationDuration = 1.0f;
s1.alpha = 0.0f;

完整示例: https ://gist.github.com/gregtemp/5086240

我知道我可以将其移至 touchesEnded 方法,但我想避免这样做。

4

1 回答 1

1

在您的问题中,您要问如何:

  1. 更新对象的属性
  2. 移动它
  3. 更新同一对象的属性
  4. 淡出

...这样当您触摸屏幕时它可以重新出现在另一个地方。

此外,你想用一种方法来做到这一点......

我建议采取不同的方法来解决这个问题。

首先,尝试将形状视为在您删除或处置它们之前一直存在的对象。基本上,您可以将对象视为将传递给各种方法的事物。

当您开始这样思考时,您可以使用以下技术来制作您正在寻找的效果:

#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

这是做什么的:

  1. 获得接触点
  2. 将触摸点传递给创建形状的方法
  3. 将创建的形状传递给淡出它的方法
  4. 当它消失时从画布中删除形状
  5. 形状从屏幕上删除后会自动从内存中删除
于 2013-03-04T22:45:55.197 回答