I have a UINavigationController that has a bottom toolbar which I set it's height programatically like so:
我有一个UINavigationController有一个底部工具栏,我以编程方式设置它的高度,如下所示:
navigationController?.toolbar.frame.size.height += 43.0
navigationController?.toolbar.frame.origin.y -= 43.0
navigationController?.hidesBarsOnTap = true
When I tap on my View to hide the bars and tap again to show them, the bottom bar returns to it's default state:
当我点击我的视图以隐藏条形并再次点击以显示它们时,底部栏返回到它的默认状态:
How can I preserve the height after the bar shows again?
如何再次显示栏后保留高度?
Thanks a lot! :)
非常感谢! :)
1 个解决方案
#1
1
There's not a great way to do that, but you can do something like place a tapGestureRecognizer on self.view and count the number of taps.
没有一个很好的方法可以做到这一点,但你可以做一些事情,比如在self.view上放置一个tapGestureRecognizer并计算点击次数。
Something like
var numTaps = 0
@IBAction func tapOnView(sender: UITapGestureRecognizer) {
self.numTaps++
if numTaps%2==0
{
self.navigationController?.toolbar.frame.size.height += 43.0
self.navigationController?.toolbar.frame.origin.y -= 43.0
}
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool{
return true
}
It is a little hackish but might work, might try with a slight delay to ensure you set the height after the toolbar's position is set.
它有点hackish但可能会工作,可能会稍微延迟,以确保您在工具栏的位置设置后设置高度。
Or try one of the answers provided Is there a way to change the height of a UIToolbar? and subclass uitoolbar to override sizeThatFits
或尝试提供的答案之一有没有办法改变UIToolbar的高度?和子类uitoolbar重写sizeThatFits
#1
1
There's not a great way to do that, but you can do something like place a tapGestureRecognizer on self.view and count the number of taps.
没有一个很好的方法可以做到这一点,但你可以做一些事情,比如在self.view上放置一个tapGestureRecognizer并计算点击次数。
Something like
var numTaps = 0
@IBAction func tapOnView(sender: UITapGestureRecognizer) {
self.numTaps++
if numTaps%2==0
{
self.navigationController?.toolbar.frame.size.height += 43.0
self.navigationController?.toolbar.frame.origin.y -= 43.0
}
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool{
return true
}
It is a little hackish but might work, might try with a slight delay to ensure you set the height after the toolbar's position is set.
它有点hackish但可能会工作,可能会稍微延迟,以确保您在工具栏的位置设置后设置高度。
Or try one of the answers provided Is there a way to change the height of a UIToolbar? and subclass uitoolbar to override sizeThatFits
或尝试提供的答案之一有没有办法改变UIToolbar的高度?和子类uitoolbar重写sizeThatFits