我想获取视图的位置,并且它正在进行动画并从一个位置移动到另一个位置 我尝试使用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秒内以如此低的速度移动。
它移动正常,但打印不正确。