ios - 如何以反 L 形为图像制作动画

标签 ios uiview uiviewanimation

我正在执行一项任务,我拍摄了一张图像和二十到三十个矩形单元格按钮。

对于那些矩形单元格,我将它们命名为 1,2,3,4,5,--------,30。我将矩形单元格排列成 6*7 矩阵。现在,如果我单击矩形单元格按钮 29,图像必须在该矩阵中找到最短路径才能到达单击的按钮。

我该如何执行此操作?

最佳答案

您有一张图片想要动画显示到 30 个按钮之一的位置吗?此外,您希望它不是沿对角线移动,而是先水平移动,然后垂直移动? CodaFi 的代码非常接近我会做的。我会编写一个 IBAction 方法,我将附加到所有按钮。以 CodaFi 的代码为基础开始,这是我建议的操作方法:

-(IBAction)animateImageToButton: (id) sender
{
  button = (UIButton *) sender;

  //First animate the image to the x position of the button
  CGPoint fPoint = CGPointMake(button.center.x, image.center.y);
  CGPoint sPoint = button.center;
  //animate x position first.
  [UIView animateWithDuration: 1.0f animations: ^
    {
      [image setCenter:fPoint];
    }
    completion ^(BOOL finished)
    {
      //Once that animation is complete, create 
      //a second animation to move to the button's y position
      [UIView animateWithDuration: 1.0f animations: ^
      {
        [image setCenter:sPoint];
      }];
    }];
}

该代码会将一个名为 Image 的 UIImageView 移动到被点击的按钮上。

关于ios - 如何以反 L 形为图像制作动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11094756/

相关文章:

ios - 所有这些自动布局更新方法之间有什么区别?都是必须的吗?

iphone - ABPerson 中发短信的默认电话号码

iOS removeFromSuperview 如果未添加到 superview 不会引发错误

ios - UITableView 高度变化时更新其他元素的约束

ios - Autolayout - UIButton 的固有大小不包括标题插入

ios - CGAffineTransformScale 之后的动画 CGAffineTransformTranslate 结果为 "jumping"帧

ios - 当用户拖动 MKMapView 时,如何为 UIImageView 设置动画?

ios - UIView animateWithDuration 重新开始

c# - xamarin 意图扩展与 netstandard 导致 MT2001 错误

ios - iOS 锁定屏幕中的播客 "skip"按钮