0

In a UIViewController, after I call self.view.frame.size.height = 99, how can I get back the original height of the view (without saving it in a variable)?

I thought of UIScreen.mainScreen().bounds.height, but that may not be accurate if a navigation bar or some other bar is present.

Rohit Pradhan
  • 3,867
  • 1
  • 21
  • 29
Code
  • 6,041
  • 4
  • 35
  • 75
  • Save the size before changing it in another variable. Or you could also add a property to `UIView` where you save its original height. – LinusGeffarth Jan 23 '16 at 06:35
  • A similar question: http://stackoverflow.com/questions/4874288/use-key-value-observing-to-get-a-kvo-callback-on-a-uiviews-frame – Cristik Jan 23 '16 at 06:36

2 Answers2

2

And once you changed view frame, you can't get the previous size value without additional variable.
You can save initial frame in variable and use it later.

shpasta
  • 1,913
  • 15
  • 21
0

You might be able to get the view back to its original size by making its superview perform layout:

view.superview?.setNeedsLayout()
view.superview?.layoutIfNeeded()

Then again, this might not work. It depends on what is embedding your view and how it lays out its subviews.

Generally it is a bad idea to set the frame of your view controller's root view. It is the job of that view's container (the window or the navigation controller or the tab bar controller or whatever) to set your view controller's root view's frame.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848