0

有一些利用 animateWithDuration 的示例 - 是否有任何简单示例说明如何使用此函数将图像从 A 点移动到 B 点?

4

4 回答 4

2

快速而肮脏只是为了显示它在使用中

class AppDelegate
  def application(application, didFinishLaunchingWithOptions:launchOptions)
    @window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
    @window.makeKeyAndVisible

    my_view = UIView.alloc.initWithFrame [[0, 0], [50, 50]]
    my_view.backgroundColor = UIColor.greenColor
    @window.addSubview my_view

    UIView.animateWithDuration(0.25, animations: lambda {
      new_frame = my_view.frame
      new_frame.origin = [100, 100]
      my_view.frame = new_frame
    })
    true
  end
end
于 2012-07-13T11:04:50.080 回答
0

The following code can be used for animating objects.

            my_view = UIView.alloc.initWithFrame [[0, 0], [50, 50]]
            my_view.backgroundColor = UIColor.greenColor
            view.addSubview my_view

            my_view.frame = [[0,0],[0,0]] #the position from which animation begins
            UIView.beginAnimations(nil,context:nil)
            UIView.setAnimationDuration(0.05)
            UIView.setAnimationDelay(0.2)
            UIView.setAnimationCurve(UIViewAnimationCurveEaseOut)
            my_view.frame = [[250,400],[50,50]]  # the position at which the animation ends
            my_view.backgroundColor = UIColor.blueColor #you can also change other properties while animating
            UIView.commitAnimations
于 2013-02-01T06:21:22.423 回答
0

使用方糖

frame = my_view.frame
frame.origin = point_a
my_view.frame = frame

# animating the move to point_b is EASY
my_view.move_to point_b
于 2013-02-02T18:49:50.180 回答
0

您可能还想看看沃尔特

  {
    move: "my_id",
    from: [10, 10],
    to: [50, 50]
  }
于 2013-02-23T11:21:41.677 回答