我向上帝发誓我在这里有一个流氓变量 - 我有一个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