gpt4 book ai didi

ios - 在 Swift 中重置对象位置

转载 作者:行者123 更新时间:2023-11-29 01:42:40 25 4
gpt4 key购买 nike

所以我试图在我的 resetButton 被点击后重置对象“puppy”的 y 位置。现在,当您第一次按下重置按钮时,没有任何反应。如果你第二次击中它,它会到达一个太高的奇怪位置。如果你继续击打它,物体就会停留在那个奇怪的地方。我的 IBAction 可能放错地方了吗?这是一个糟糕的代码吗?

附注- 底部注释掉的东西是我试过但没用的东西。

    class ViewController: UIViewController, ADBannerViewDelegate {

@IBAction func resetButton() {


puppy.center.y = 131




//puppy.frame = CGRectMake(puppy.frame.origin.y, 131,puppy.frame.size.width,puppy.frame.size.height)
/*UIView.animateWithDuration(0, delay: 1, options: UIViewAnimationOptions.CurveLinear, animations: {
self.puppy.alpha = 1
self.puppy.center.y = 131
}, completion: nil)*/

}

}

最佳答案

var location = CGPoint(x:0, y:131)
puppy.center = location

试试这个!在这里,您指定了一个类型为 CGPoint 的变量,然后您可以将小狗的中心设置在该位置。

关于ios - 在 Swift 中重置对象位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32236329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com