Value of type 'UILabel?' has no member 'x'というエラーが出てしまっているのですが、原因がわからないです。
「UILabelという変数にXという値がないよ」ということはわかったのですが、、、
swift
1import UIKit 2 3class Result_ViewController: UIViewController { 4 5 @IBOutlet var scoreLabel: UILabel! 6 @IBOutlet var messageLabel: UILabel! 7 @IBOutlet var nameLabel: UILabel! 8 @IBOutlet var genderLabel: UILabel! 9 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 13 // Do any additional setup after loading the view. 14 let aD: AppDelegate = UIApplication.shared.delegate as! AppDelegate 15 let score: Int = aD.score * 5 16 scoreLabel.text = "(score)%" 17 18 if score < 30{ 19 messageLabel.text = "二郎禁止レベル" 20 }else if score < 50{ 21 messageLabel.text = "プチレベル" 22 }else if score < 70{ 23 messageLabel.text = " 小レベル" 24 }else if score < 90{ 25 messageLabel.text = "小マシレベル" 26 }else if score < 100{ 27 messageLabel.text = "小マシマシレベル" 28 }else if score < 110{ 29 messageLabel.text = "大レベル" 30 }else{ 31 messageLabel.text = "野猿マシマシレベル" 32 } 33 34 35 36 nameLabel.text = aD.name+"は" 37 genderLabel.text = "ジロリアン" + aD.gender + "だ!" 38 aD.records.append( ([aD.name, aD.gender, aD.score] as AnyObject) as! [AnyObject] ) 39 40 aD.score = 0; 41 } 42 43 override func viewDidAppear(_ animated: Bool) { 44 super.viewDidAppear(true) 45 46 scoreLabel.center = CGPoint(x: scoreLabel.center.x,y: scoreLabel.center.y - 200) 47 UIView.animate(withDuration: 1.0, delay: 0, options: UIView.AnimationOptions.curveLinear, animations: { () -> Void in 48 self.scoreLabel.center = CGPoint(self.scoreLabel.x,self.scoreLabel.y + 200) }, completion: nil) 49 } 50 51 /* 52 // MARK: - Navigation 53 54 // In a storyboard-based application, you will often want to do a little preparation before navigation 55 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 56 // Get the new view controller using segue.destination. 57 // Pass the selected object to the new view controller. 58 } 59 */ 60 61} 62
以下の2行めにエラーが発生しています。
UIView.animate(withDuration: 1.0, delay: 0, options: UIView.AnimationOptions.curveLinear, animations: { () -> Void in self.scoreLabel.center = CGPoint(self.scoreLabel.x,self.scoreLabel.y + 200) }, completion: nil) }
試したこと
該当のコードの記述を
scoreLabel.center = CGPoint(x: scoreLabel.center.x,y: scoreLabel.center.y - 200)
のような形にしてみたが、エラーでfixしました。
足りない情報などありましたら教えていただけるとありがたいです。
正直、どこから手をつけて良いのかわからなかったのでご教授いただきたいです????♂️
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/17 06:40