【问题标题】:Make image move more "fluidly"让图像移动更“流畅”
【发布时间】:2012-08-04 04:19:56
【问题描述】:

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

这是我所拥有的:

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

【问题讨论】:

  • 查看动画。我不使用 iOS,但 UIView 的 beginAnimation: 等可能值得一看?

标签: objective-c ios cocoa-touch uiimageview


【解决方案1】:

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

[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
    }
}];

【讨论】:

  • 它到底有什么帮助?
  • @user1438042 它做的一切都是一样的,我只是认为这是一种更简洁、更有条理的动画执行方式。
  • +1 文档明确说要为 iOS4+ 使用基于块的动画方法
【解决方案2】:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

y = y + 10;
myImageView.frame = CGRectMake(x, y, 45, 56);        
[UIView commitAnimations];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 1970-01-01
    相关资源
    最近更新 更多