我想獲取視圖的位置,並且它正在進行動畫並從一個位置移動到另一個位置 我嘗試使用presentationLayer獲取動作位置信息 並試圖在UIView移動時打印出位置。爲什麼視圖的presentationLayer對我無法正常工作?
這裏是正在打印:
2010-12-08 16:56:50.496 Exp[31219:207] point: NSPoint: {45, 45}
2010-12-08 16:56:50.696 Exp[31219:207] point: NSPoint: {45, 45}
2010-12-08 16:56:50.896 Exp[31219:207] point: NSPoint: {45, 45}
2010-12-08 16:56:51.096 Exp[31219:207] point: NSPoint: {45, 45}
2010-12-08 16:56:51.296 Exp[31219:207] point: NSPoint: {45, 45}
2010-12-08 16:56:51.496 Exp[31219:207] point: NSPoint: {245, 245} <<----------------------------------------
2010-12-08 16:56:51.696 Exp[31219:207] point: NSPoint: {245, 245}
2010-12-08 16:56:51.896 Exp[31219:207] point: NSPoint: {245, 245}
2010-12-08 16:56:52.096 Exp[31219:207] point: NSPoint: {245, 245}
通知的箭頭,該端點被直接打印出來,而不顯示路徑上的點。誰能幫忙?
下面是我的代碼:
下面是它是如何印刷:
-(void)print
{ NSLog([NSMutableString stringWithFormat:@"point: %@",[NSValue valueWithCGPoint:((CALayer *)[bomb.layer presentationLayer]).position]]);
}
我用了一個定時器可重複打印出來的動畫視圖 「炸彈」
-(id)initWithCoder:(NSCoder *)aDecoder
{ if (self=[super initWithCoder:aDecoder]) {
bomb = [[BombView alloc]init];
bomb.frame = CGRectMake(30, 30, 30, 30);
bomb.backgroundColor = [UIColor yellowColor];
[self addSubview:bomb];
timer = [NSTimer timerWithTimeInterval:PRINTINTERVAL // defined to be 0.2
target: self
selector: @selector(print)
userInfo: nil
repeats: YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode: NSDefaultRunLoopMode];
}
return self;
}
這是它的動畫: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.duration = 10.0;
animation.delegate = bomb;
[bomb.layer addAnimation:animation forKey:@"animatePosition"];
bomb.center = CGPointMake(bomb.center.x+200, bomb.center.y+200);
}
當我點擊時,「炸彈」會移動,打印出的信息應該逐漸改變。因爲它在10秒內以如此低的速度移動。
它移動正常,但打印不正確。