gpt4 book ai didi

ios - Objective-C: block 中的动画

转载 作者:搜寻专家 更新时间:2023-10-30 20:16:24 25 4
gpt4 key购买 nike

我有一个 UIImageView sliderPump,我通过一个接一个地调用两个方法从屏幕的右侧移动到左侧无限次:

    -(void)pumpGoesRight
{
if (slide)
{
[UIView animateWithDuration:0.8 animations:^
{

[sliderPump setFrame:CGRectMake(sliderPump.frame.origin.x+235, sliderPump.frame.origin.y, sliderPump.frame.size.width, sliderPump.frame.size.height)];

} completion:^(BOOL finished)
{
[self pumpGoesLeft];
}];
}
else
return;
}
-(void)pumpGoesLeft
{
if (slide)
{

[UIView animateWithDuration:0.8 animations:^
{
[sliderPump setFrame:CGRectMake(sliderPump.frame.origin.x-235, sliderPump.frame.origin.y, sliderPump.frame.size.width, sliderPump.frame.size.height)];

} completion:^(BOOL finished)
{
[self pumpGoesRight];
}];

[self performSelector:@selector(pumpGoesRight) withObject:nil afterDelay:0.8];
}
else
return;

}

然后我使用这段代码找出 UIImageView sliderPumpX 位置并停止动画:

-(void)stop
{
slide = NO;
NSLog(@"Slide Pump position: %f", sliderPump.layer.frame.origin.x);
[self.view.layer removeAllAnimations];
}

问题是,当我调用 stop 方法时,我想得到 sliderPump 的当前位置,但我得到的是 sliderPimp 的最终位置动画结束,即使动画还没有完成。我怎样才能得到框架的当前位置?谢谢!

最佳答案

你应该使用表现层。

NSLog(@"Slide Pump position: %f", [sliderPump.layer.presentationLayer frame].origin.x);

关于ios - Objective-C: block 中的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28817384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com