我向上帝發誓我在這裏有一個流氓變量 - 我有一個bool menuUp
,它只是告訴你某些菜單按鈕是否已經移動了。Swift - 布爾的價值被改變而沒有做任何事情?不能找到它被改變的地方?
我首先聲明bool爲false,然後根據bool(如果菜單已啓動或未啓動),動畫將在滑動手勢/函數上運行。
var menuUp = Bool(false) //at class level
我已經設置了許多斷點和打印報表,但它好像在布爾正在沒有我做任何修改。當應用程序加載時,我有我的超級視圖控制器調用此函數,打印以下內容並使menuup
爲真。
func moveMenuUp(sender: AnyObject!)
{
print("menu up:")
print(menuUp)
if !menuUp && !externalViewUp
{
UIView.animateWithDuration(0.8, delay: 0.0, usingSpringWithDamping:
0.65, initialSpringVelocity: 1.2, options: [], animations: {
//above change the duration to the time it will take,
//and fiddle with the springs between 0-1 until you are happy with the effect.
self.menuBtn1.center.y -= screenSize.height * (122/568)
self.menuBtn2.center.y -= screenSize.height * (122/568)
self.menuBtn3.center.y -= screenSize.height * (122/568)
//chnage frame however you want to here
}, completion: { finished in
//code that runs after the transition is complete here
})
menuUp = !menuUp
}
print(menuUp)
}
所以它的真實。大。然後在另一個類我引用這個超級viecontorller這樣和一個按鈕嘗試調用關機功能菜單,也可通過向下滑動超級視圖控制器上叫做 -
let superv : StarterViewController = StarterViewController (nibName: "StarterViewController", bundle: nil)
然後
func showIdeaView()
{
networkTimer.invalidate()
superv.moveMenuDown(self) //THIS NEEDS WORK!! BOOL ISSUES!
externalViewUp = true
viewGestureRecognizer.enabled = false
self.addChildViewController(v)
self.view.addSubview(v.view)
v.didMoveToParentViewController(self)
v.view.frame = self.view.bounds
self.view.bringSubviewToFront(v.view)
}
這就要求
func moveMenuDown(sender: AnyObject!)
{
print("moving down!!!")
print(menuUp)
if menuUp == true {
UIView.animateWithDuration(0.8, delay: 0.0, usingSpringWithDamping:
0.65, initialSpringVelocity: 1.2, options: [], animations: {
//above change the duration to the time it will take,
//and fiddle with the springs between 0-1 until you are happy with the effect.
self.menuBtn1.center.y += screenSize.height * (122/568)
self.menuBtn2.center.y += screenSize.height * (122/568)
self.menuBtn3.center.y += screenSize.height * (122/568)
//chnage frame however you want to here
}, completion: { finished in
//code that runs after the transition is complete here
})
menuUp = !menuUp
}
print(menuUp)
}
而這個函數被調用但它打印 - 而在調用上述函數的函數的開頭我打印出了布爾值,這裏也是假的。
奇怪的是,當我用滑動觸發moveMenuDown
時,它輸出正確(開始爲真,結束爲假)。
菜單仍然清晰起來我可以看到它,所以我知道bool不應該/不是假的。
因爲它將ht bool讀爲false,所以它不調用動畫並將其向下移動到moveMenuDown
中。這是一個主要問題。
我能在這裏做什麼?我嘗試點擊放大鏡找到所有我參考bool的地方,但是我不會在超級視圖控制器以外的任何地方改變它,我只在這兩個函數中改變了TWICE。
怎麼回事?
編輯:
我現在在班上寫在其他子視圖控制器超級視圖控制器和伊夫有weak var superv: StarterViewController!
:
let s = StarterViewController()
,並在viewDidLoad中:
s.superv = self
當初始化一個'StarterViewController',你確定你沒有初始化'menuUp'的第二個實例? –
你可以添加一個斷點,當它的值發生變化時 – Gruntcakes
@SausageDioxide我該怎麼做?我不熟悉斷點 – skyguy