[英]Sliding a UIView down and then back up
I have a UIView that is will slide down on button tap and then slide back up on another button tap. 我有一个UIView,它将在按钮点击时向下滑动,然后在另一个按钮点击时向上滑动。 It slides down perfectly, but when I try to hit the contract button, I can't click it, but it does click a collection view cell that is underneath the view. 它可以完美地向下滑动,但是当我尝试点击合同按钮时,我无法单击它,但是它确实单击了该视图下方的集合视图单元格。 I can't figure out why it slides down properly but it doesn't function how I expect. 我不知道为什么它会正确滑下,但无法发挥我的预期。 Thanks a lot! 非常感谢!
@IBAction func onExpandButtonPressed(sender: UIButton) {
let xPosition = expandingView.frame.origin.x
//View will slide to 40 px higher bottom of the screen
let yPosition = expandingView.frame.maxY - 40
let height = expandingView.frame.size.height
let width = expandingView.frame.size.width
UIView.animateWithDuration(0.5, animations: {
self.expandingView.frame = CGRectMake(xPosition, yPosition, height, width)
self.expandButton.hidden = true
self.contractButton.hidden = false
})
}
@IBAction func onContractButtonPressed(sender: UIButton) {
let xPosition = expandingView.frame.origin.x
let yPosition = expandingView.frame.origin.y
let height = expandingView.frame.size.height
let width = expandingView.frame.size.width
UIView.animateWithDuration(1.0, animations: {
self.expandingView.frame = CGRectMake(xPosition, yPosition, height, width)
self.expandButton.hidden = false
self.contractButton.hidden = true
})
}
Perhaps it's because the view has slid over the button. 也许是因为视图已经滑过按钮。 So try to use the following inside the button action that will slide over the non-working button: 因此,请尝试在将要在无效按钮上滑动的按钮动作中使用以下命令:
self.view.bringSubViewToFront(buttonName)
If you put an NSLog inside your button Action, it can help determine if the function is being called. 如果将NSLog放在按钮Action中,则可以帮助确定是否正在调用该函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.