【发布时间】:2016-07-18 02:43:45
【问题描述】:
我向上帝发誓,我这里有一个流氓变量——我有一个布尔值menuUp,它简单地告诉我们某些菜单按钮是否被上移了。
我首先将 bool 声明为 false,然后根据 bool(菜单是否打开),动画将在滑动手势/功能上运行。
var menuUp = Bool(false) //at class level
我已经设置了许多断点和打印语句,但似乎 bool 正在被修改而我没有做任何事情。当应用程序加载时,我的超级视图控制器调用此函数,打印以下内容并使 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 中向下移动菜单。这是个大问题。
我可以在这里做什么?我试过点击放大镜来找到我引用布尔的所有地方,但我不会在超级视图控制器之外的任何地方更改它,我只在这两个函数中更改了两次。
怎么了?
编辑:
我现在在超级视图控制器的类中有weak var superv: StarterViewController!,我已经在另一个子视图控制器中编写了:
let s = StarterViewController()
在viewdidLoad中:
s.superv = self
【问题讨论】:
-
当您初始化
StarterViewController时,您确定没有初始化menuUp的第二个实例吗? -
可以添加断点,在其值发生变化时中断
-
@SausageDioxide 我该怎么做?我不精通断点
-
在
menuUp上实现didSet属性观察器,并在其中设置断点。看看你是否能发现意想不到的变化。 -
这可能..如果我在 parentviewcontroller 上调用 moveMenuDown 而不是 superv 我设置它的方式我仍然会这样做还是..正确的方法是什么