gpt4 book ai didi

ios - 用户界面标签!出现而不是隐藏在 Swift 中

转载 作者:行者123 更新时间:2023-11-30 14:05:26 26 4
gpt4 key购买 nike

我试图在游戏获胜之前让我的标 checkout 现在屏幕上。当游戏获胜时,我希望标 checkout 现在屏幕上。我正在使用 UIView.animateWithDuration 和 viewDidAppear 方法。我认为这与 viewDidAppear 有关。

import UIKit

class ViewController: UIViewController {

//All the odd numbers will be noughts & even will be crosses
var goNumber = 1
var winner = 0

//0 = empty, 1 = nought, 2 = cross
var gameState = [0, 0, 0, 0, 0, 0, 0, 0, 0]

let winningCombinations = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]

@IBOutlet weak var button0: UIButton!
@IBOutlet weak var winnerLabel: UILabel!
@IBOutlet weak var label: UILabel!

@IBAction func buttonPressed(sender: AnyObject) {
var image = UIImage()

if gameState[sender.tag] == 0 {
println(sender.tag)

if goNumber % 2 == 0 {
image = UIImage(named: "cross.png")!
gameState[sender.tag] = 2
} else {
image = UIImage(named: "nought.png")!
gameState[sender.tag] = 1
}

for combination in winningCombinations {
if (gameState[combination[0]] == gameState[combination[1]] && gameState[combination[1]] == gameState[combination[2]]) && gameState[combination[0]] != 0 {
winner = gameState[combination[0]]
}
}

if winner != 0 {
println("We have a winner")

label.text = (winner == 1) ? "Noughts has won" : "Crosses has won"

UIView.animateWithDuration(1) {
self.label.center = CGPointMake(self.label.center.x + 400, self.label.center.y)
}
}

goNumber++
sender.setImage(image, forState: .Normal)
}
}

override func viewDidAppear(animated: Bool) {
label.center = CGPointMake(label.center.x - 400, label.center.y)
}
}

最佳答案

试试这个,

swift 2

UIView.animateWithDuration(1, delay: 0, options: CurveEaseOut, animations: {

self.label.center = CGPointMake(self.label.center.x + 400, self.label.center.y)

}, completion : nil)

swift 3、4、5

UIView.animate(withDuration: 1, delay: 0, options: .curveEaseOut, animations: {

self.label.center = CGPoint(x: self.label.center.x + 400, y: self.label.center.y)

}, completion : nil)

关于ios - 用户界面标签!出现而不是隐藏在 Swift 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32490949/

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