UIView 在 Animatoin 期间获取位置
我已经在 Stack 以及其他各种网站上查看了这个问题的每个实例,但它仍然不适合我。我试图在动画会话期间获取对象的位置。
这是我所拥有的:
- (void)viewDidLoad{
currentPosition = [[bikeMotion.layer presentationLayer] center]; //its a CGPoint
}
- (void)doAnimation {
bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
//... [self animate stuff]...
[NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}
-(void)backgroundAnimations{
cout << currentPosition.x << endl;
}
我也尝试过这个:
- (void)viewDidLoad{
currentPosition = [[bikeMotion.layer presentationLayer] frame]; //its a CGRect
}
- (void)doAnimation {
bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
//...[self animation stuff];
[NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}
-(void)backgroundAnimations{
cout << currentPosition.origin.x << endl;
}
我什至尝试过这个:
- (void)viewDidLoad{
p = (CALayer*)[bikeMotion.layer presentationLayer];
}
-(void)doAnimation{
bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
[NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}
-(void)backgroundAnimations{
CGPoint position = [p position];
cout << position.x << endl;
}
I have looked at every instance of this question on Stack as well as various other websites, its still not working out for me. I am trying to get the position of my object while the animation is in session.
Here is what I have:
- (void)viewDidLoad{
currentPosition = [[bikeMotion.layer presentationLayer] center]; //its a CGPoint
}
- (void)doAnimation {
bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
//... [self animate stuff]...
[NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}
-(void)backgroundAnimations{
cout << currentPosition.x << endl;
}
I also tried this:
- (void)viewDidLoad{
currentPosition = [[bikeMotion.layer presentationLayer] frame]; //its a CGRect
}
- (void)doAnimation {
bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
//...[self animation stuff];
[NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}
-(void)backgroundAnimations{
cout << currentPosition.origin.x << endl;
}
I have even tried this:
- (void)viewDidLoad{
p = (CALayer*)[bikeMotion.layer presentationLayer];
}
-(void)doAnimation{
bikeMotion = [[DotAnimation alloc]initWithFrame:CGRectMake((*bikePathPoints)[0].x, (*bikePathPoints)[0].y, 8, 8)];
[NSTimer scheduledTimerWithTimeInterval:0.07f target:self selector:@selector(backgroundAnimations) userInfo:nil repeats:YES];
}
-(void)backgroundAnimations{
CGPoint position = [p position];
cout << position.x << endl;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过
object.layer.anchorpoint
吗?您需要导入 QuartzCore。Have you tried
object.layer.anchorpoint
? You'll need to import QuartzCore.