IOS UIView `convertRect: toView:` does not work as expected

I have an old iOS code and now I am switching to sdk7. I have to support iOS5 (so there is no auto layout). The code creates some parts of the user interface dynamically (by code).

To cope with the fact that the navigation view may overlap with the navigation bar, I made this code:

-(void) viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];

  CGRect navBarRect = self.navigationController.navigationBar.bounds; // 1
  CGPoint bottomLeft = [self.navigationController.navigationBar convertPoint: CGPointMake(0, CGRectGetMaxY(navBarRect))
                                                                      toView: self.view]; // 2
  navBarRect = [self.navigationController.navigationBar convertRect: navBarRect
                                                             toView: self.view]; // 3

  DDLogVerbose(@"Test positions bottomLeft=%@ navBarRect=%@",
               NSStringFromCGPoint(bottomLeft), NSStringFromCGRect(navBarRect));

  CGFoat localTop = CGRectMaxY(navBarRect);
  CGRect frame = self.view.bounds;
  ...

This one localTopsuppose that I give the right position ywhere I can start adding my articles independent of the iOS version and believe that they are resistant to any new inventions by Apple.

. , 1, ({0, 0}, {320, 44}). 3 navBarRect {0, 20} (self.view , ), {640, 88} , . convertPoint:toView ( 2), .

self.view , , , 3?

(lldb) po self.view
<UIView: 0x1d9ac1f0; frame = (0 0; 320 411); layer = <CALayer: 0x1d9acae0>>
(lldb) po [self.view superview]
<UIViewControllerWrapperView: 0x1d9b5b20; frame = (0 20; 320 411); layer = <CALayer: 0x1d9b5b80>>
(lldb) po [[self.view superview] superview]
<UINavigationTransitionView: 0x1d9aa040; frame = (0 0; 320 431); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x1cd2a470>>
(lldb) po [[[self.view superview] superview] superview]
<UILayoutContainerView: 0x1cd207c0; frame = (0 0; 320 431); autoresize = W+H; layer = <CALayer: 0x1d975980>>
(lldb) po [self.navigationController navigationBar]
<UINavigationBar: 0x1cd08d60; frame = (0 20; 320 44); clipsToBounds = YES; opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0x1cd09400>; layer = <CALayer: 0x1cd09070>>
(lldb) po [[self.navigationController navigationBar] superview]
<UILayoutContainerView: 0x1cd207c0; frame = (0 0; 320 431); autoresize = W+H; layer = <CALayer: 0x1d975980>>

, , ( )?

+4

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


All Articles