How to get * the actual frame size for a UIScrollView in a UINavigationController in iOS 7?

So it seems that the presentation frame in the navigation controllers of iOS 7 is defined differently (in my opinion, strange) compared to iOS 7 ...

EXAMPLE: Imagine a UIViewController that contains a UIScrollView ( self.scrollView ) that fills the entirety of self.view and with spacers and springs so that it always self.view . Now insert this UIViewController into the UINavigationController with a visible navigation bar.

In iOS 6, I observe the following:

  • self.view.frame.origin = (0.0, X) where X = the height of the status bar (which contains time, signal bands, etc. = 20.0 )
  • self.view.frame.size.height = self.view.bounds.size.height = total height minus self.navigationController.navigationBar.frame.size.height
  • self.scrollView.frame.origin = self.scrollView.bounds.origin = (0.0, 0.0)

In iOS 7, I observe the following:

  • self.view.frame.origin = (0.0, 0.0)
  • self.view.frame.size.height = self.view.bounds.size.height = total height (i.e. decreasing height when embedded in the navigation controller)
  • self.scrollView.bounds.origin = (0.0, -1 * self.navigationController.navigationBar.frame.size.height) , but self.scrollView.frame.origin = (0.0, 0.0)

My guess is that this is done so that the content can remain under the navigation bar, so that the smallest amount of blur + transparency a la iOS 7 is displayed on the navigation bar.

QUESTION: How can I get the actual size (width x height) of self.scrollView in iOS 7 when it is built into the navigation controller, given the above observations, since self.scrollView.bounds.origin == self.scrollView.contentOffset ? I just need to write different code for iOS 6 v. IOS 7 and determine which version works?

I really do not want to assume that there is any specific size and hard code on the screen, because it looks like a bad shape ...


UPDATE 1: I uploaded a sketch of what I'm trying to ask. Please note that the correct answer in this case is 416.0 , which is easy to get in iOS 6, but I'm not sure how to get it in iOS 7 without resorting to assumptions.

Screenshots, iOS 6 v. iOS 7 Layout

+6
source share
2 answers

What happens is that your UITableView automatically configured so that the content is displayed behind the UINavigationBar on iOS 7. This is done by changing the contentInset property found in UIScrollView . Thus, in order to get the frame, excluding the part behind the nav / status panel, you just need to consider the contentInset .

 CGRect frame = self.tableView.frame; frame.origin.y += self.tableView.contentInset.top frame.size.height -= self.tableView.contentInset.top; 

This code will also work on iOS 6 because self.tableView.contentInset.top will default to 0.

+9
source

On iOS7, you need to set UIScrollView.contentInset.bottom/top according to UIViewController.bottomLayoutGuide/topLayoutGuide.length .

0
source

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


All Articles