简体   繁体   English

获取动画UIImageview的坐标

[英]get coordinates of animated UIImageview

I am animating an UIImageview in horizontal position for this purpose i have used the below code i have used the NSTimer 我为了这个目的在水平位置制作动画UIImageview我已经使用了下面的代码我使用了NSTimer

timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

-(void)onTimer
{
    [UIView animateWithDuration:10.0f animations:^{
          //Moving_Cloud is an image view
            Moving_Cloud.frame = CGRectMake(200.0f, 150.0f, Moving_Cloud.frame.size.width, Moving_Cloud.frame.size.height);
           }];

}

now the problem i am facing is i need to get the coordinates of the "Moving_Cloud" after the animate duration 现在我面临的问题是我需要在动画持续时间后得到“Moving_Cloud”的坐标
please help me 请帮我
Thanks in advance. 提前致谢。

[UIView animateWithDuration:10.0f animations:^{
    Moving_Cloud.frame = CGRectMake(200.0f, 150.0f, Moving_Cloud.frame.size.width, Moving_Cloud.frame.size.height);
} completion:^(BOOL finished){
    CGPoint newPost = Moving_Cloud.frame.origin;
    CGFloat xPos = newPost.x;
    CGFloat yPos = newPost.y;
    // do stuff ?
}];

At the end of your animation the block "completion:" will be trigger. 在动画结束时,将触发“完成:”块。
Normally your image should be in x = 200, y = 150. 通常你的图像应该是x = 200,y = 150。

Be aware that those coordinates are relative to it superview (the view wrapping Moving_Cloud view). 请注意,这些坐标是相对于它的superview(视图包装Moving_Cloud视图)。

Note: 注意:
By convention I recommend changing "Moving_Cloud" to "movingCloud". 按照惯例,我建议将“Moving_Cloud”更改为“movingCloud”。
Instance class start in lower cap in objective-C. 实例类以objective-C中的较低上限开始。
Also don't use _ but a capital letter instead. 也不要使用_而是使用大写字母。

Abhijit Chaudhari from the comment in my previous post I understand that what you want is not the position "after the animate duration" but instead the position during the animation. Abhijit Chaudhari来自我之前的帖子中的评论我明白你想要的不是“动画持续时间之后”的位置而是动画期间的位置。

If I still didn't get it right please clarify your question. 如果我仍然没有做对,请澄清你的问题。 (Or buy me an new brain) (或者给我一个新的脑子)

-(void) animateMe(){
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
    [UIView animateWithDuration:10.0f animations:^{
         //Moving_Cloud is an image view
         Moving_Cloud.frame = CGRectMake(200.0f, 150.0f, Moving_Cloud.frame.size.width, Moving_Cloud.frame.size.height);
    }];
}

-(void)onTimer:(id)sender{
    NSLog(@"Currently in x=%f", [[ddddd.layer presentationLayer] frame].origin.x);
    NSLog(@"Currently in y=%f", [[ddddd.layer presentationLayer] frame].origin.y);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM