我正在执行一项任务,我拍摄了一张图像和二十到三十个矩形单元格按钮。
对于那些矩形单元格,我将它们命名为 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/