gpt4 book ai didi

objective-c - 使图像移动更多 "fluidly"

转载 作者:行者123 更新时间:2023-11-28 18:13:22 26 4
gpt4 key购买 nike

我想制作一个 IBAction,调用它时会使图像“流畅地”移动一定数量的像素。我现在有一个可以使图像向左移动 10 个像素,但它只是传送到那里。我想让图像移动,就像它在行走一样,而不是神奇地停在那里。

这是我的:

- (IBAction)moveImageLeft:(id)sender
{
y = y + 10;
myImageView.frame = CGRectMake(x, y, 45, 56);
}

最佳答案

@Dimple 的回答是正确的。但是,仅供引用,这是另一种方法。它被称为动画 block ,在我看来,它使整个动画过程变得更加容易。

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
y = y + 10;
myImageView.frame = CGRectMake(x, y, 45, 56);
}completion:^(BOOL finishedAnimating){
if (finishedAnimating == YES) {
NSLog(@"animation finished");//you can put your own completion handler events here
}
}];

关于objective-c - 使图像移动更多 "fluidly",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11805865/

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