Increase and revitalize the height of the navigation bar?

I have subclassed the UINavigationBar, and I have a button that gets into the drop-down menu. I want to animate and click the content below the navigation bar as the height of the navigation bar increases. Essentially, I need a temporary table in the navigationBar view.

So far, I have redefined sizeThatFits () to return custom sizes for the required length, which is determined by state enumeration. And I call sizeToFit () when the navigation bar needs to be resized.

override func sizeThatFits(size: CGSize) -> CGSize { let superSize = super.sizeThatFits(size) var newSize: CGSize! if(state == .Normal) { newSize = CGSizeMake(superSize.width, superSize.height + heightIncrease) } else if (state == .Menu) { newSize = CGSizeMake(superSize.width, superSize.height + tableIncrease) } return newSize } func buttonPressed(){ if(state == .Normal){ state = .Menu _delegate?.didChangeStateTo(.Menu) } else if (state == .Menu){ state = .Normal _delegate?.didChangeStateTo(.Normal) } UIView.animateWithDuration(0.3, animations: { self.sizeToFit() }) } 

When I'm animating sizeToFit (), the navigation bar grows in size to fit the animation, but the content under the panel (viewController view) immediately goes to full length.

This is because sizeThatFits immediately returns a new CGSize. Thus, the animation works only for the navigation bar itself, and the content of the view does not follow the animation, but goes to the destination.

I tried to avoid using sizeThatFits, but the UINavigationBar does not allow you to resize the panel by simply setting the frame with CGRect.

I know that there are other ways to get around this without playing with the UINavigationBar subclassification, but with my application user interface this method will be the most efficient and effective for the code.

Thanks in advance

+5
source share

Source: https://habr.com/ru/post/1210459/


All Articles