I have some old iOS code and now I'm migrating to sdk7. I have to support iOS 5 (so no auto layout). Code creates some parts of UI dynamically (by code).
To handle possibility that navigation view can overlap with navigation bar I did 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 localTop
suppose to give me proper y
position where I can start add my items independent on iOS version and suppose to be resistant to any new Apple inventions.
But this doesn't work. Line marked as 1
gives proper bounds ({0, 0}, {320, 44})
. But then after executing line 3
top left corner of navBarRect
is {0, 20}
(self.view overlaps with navigation bar and status bar so this is expected) but its size is {640, 88}
so double of that what is expected.
I also tried version with convertPoint:toView
(line 2
) but this give me same result.
I've checked all superviews of navigation and and self.view
up to the common view and I didn't found any transformation so how it is possible that this frame changed size after line 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>>
Or maybe there is better solution (no hard coding)?