Correct Way To Move UIButton Between Two Points?

陌路散爱 提交于 2019-12-03 21:37:58

viewDidLoad occurs before the view is visible so it will move just not animated. You could try putting it in the viewDidAppear method.

You can wrap things in UIView animation blocks like so if you want them to animate instead of blink into position.

[UIView animateWithDuration:0.5 animations:^{
    button.center = CGPointMake(200.0, 200.0);
}];

Since you're using interface builder I'm assuming your using properties to keep track of the buttons. This can work if you're only using a few set buttons but I'd expect in a game those will change so you may want to move to code or atleast use IBOutletCollections to keep track of the buttons.

Swift 3.0

UIView.animate(withDuration: 0.5) { [weak self] in
    self?.button.center = CGPoint(x: 200, y: 200)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!