0
可怕的標題道歉,但我真的想不出有更好的方式來表達它。我的代碼如下:Swift - 即使它們可見,也不顯示/更新控件
@IBAction func btnSaveTapped(sender: UIButton) {
println("Save Button Pressed")
self.StartAI()
self.btnSave.enabled = false
self.AnimateButton(sender)
var booContinueWithSend:Bool = true
(Continues)
當我運行上面的代碼時,屏幕上的控件沒有改變。我已經通過代碼和每一行,沒有改變。即使是btnSave.enabled
,也沒有變化。我已經通過控制檯調試器po
確認該按鈕未啓用,但它仍然顯示爲好像它。是的,我已經將它設置爲明顯取決於狀態(下面的代碼)改變:
self.btnSave.setTitleColor(conButtonTextColour, forState: UIControlState.Normal)
self.btnSave.setTitleColor(conButtonTextColourDisabled, forState: UIControlState.Disabled)
其中conButtonTextColour
是UIColor.blackColor
和conButtonTextColourDisabled
是灰色的。
它也發生在我的活動指標,我已經手動測試成功。當我運行上面的代碼(btnSaveTapped
)時,沒有任何反應(它不顯示它應該)。我在這裏以編程方式創建AI:
func CreateAI() {
let conAIViewHeightWidth:CGFloat = 100
let conHeightWidth:CGFloat = 50
self.aiView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubview(self.aiView)
self.aiView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3)
self.aiView.layer.cornerRadius = 10
var constraintViewHeight:NSLayoutConstraint = NSLayoutConstraint(item: self.aiView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: conAIViewHeightWidth)
var constraintViewWidth:NSLayoutConstraint = NSLayoutConstraint(item: self.aiView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: conAIViewHeightWidth)
self.aiView.addConstraints([constraintViewHeight, constraintViewWidth])
var constraintViewX:NSLayoutConstraint = NSLayoutConstraint(item: self.aiView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
var constraintViewY:NSLayoutConstraint = NSLayoutConstraint(item: self.aiView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)
self.view.addConstraints([constraintViewX, constraintViewY])
self.aiActivityIndicator.setTranslatesAutoresizingMaskIntoConstraints(false)
self.aiView.addSubview(self.aiActivityIndicator)
self.aiActivityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge
var constraintX:NSLayoutConstraint = NSLayoutConstraint(item: self.aiActivityIndicator, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: self.aiView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0)
var constraintY:NSLayoutConstraint = NSLayoutConstraint(item: self.aiActivityIndicator, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: self.aiView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0)
self.view.addConstraints([constraintX, constraintY])
self.aiActivityIndicator.hidesWhenStopped = true
self.aiActivityIndicator.startAnimating()
StopAI()
}
這裏是我的兩個例程分別啓動和停止AI。因爲AI是aiView
的子視圖,我只是隱藏或取消隱藏。但是,由於這些問題,我決定保證安全,並確保我隱藏並啓用了AI。
func StartAI() {
self.aiView.hidden = false
self.aiActivityIndicator.hidden = false
self.aiActivityIndicator.startAnimating()
println("Started AI")
}
func StopAI() {
self.aiView.hidden = true
println("Stopped AI")
}
我在做什麼錯? 在此先感謝。
此。您可能已經爲某些元素添加了約束條件,並留下了一些無約束條件的視圖,從而導致視圖無法互動 – Krishna