0

I am using translucent navigation controller in my ios app.

The problem is that my CollectionViewcontroller moves under the translucent NavigationController. But when i change it to blacknavigationController then it gets corrected.

I want the translucentNavigationController to behave like blackNavigationController? I dont know how to achieve this?

Thank you. enter image description here

enter image description here

I have already tried adding section header to collection view but the problem with that is upon device rotation the size of header remains same.

MY Rotation Handling COde @j_mcnally

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{

    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication]  statusBarOrientation];
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    {
        NSLog(@"Is in portrait Mode");
        self.collectionView.contentInset=UIEdgeInsetsMake(44.0f, 0.0f, 0.0f, 0.0f);
        self.collectionView.scrollIndicatorInsets=UIEdgeInsetsMake(45.0f, 0.0f, 0.0f,  0.0f);
    }
    else{
        NSLog(@"Is in landscape Mode");

        self.collectionView.contentInset=UIEdgeInsetsMake(32.0f, 0.0f, 0.0f, 0.0f);
        self.collectionView.scrollIndicatorInsets=UIEdgeInsetsMake(33.0f, 0.0f, 0.0f,  0.0f);
}

}

With rotation handling the problem seems to be fixed unless i do a left rotation and then right rotation. Then the result is this enter image description here

Muhammad Nasir
  • 1,796
  • 1
  • 14
  • 22
  • did you try adjusting the .alpha property? You can take the black navbar and set alpha to like 0.2f or something to emulate the other. – apollosoftware.org Mar 25 '13 at 20:01
  • i think the issue here, is there is still black draw behind the navbar as the scrollview frame would start below the header. – j_mcnally Mar 25 '13 at 20:10
  • ahh i see now. Well the issue here is not an issue. its jsut moved your view to 32.0f and when u rotate it back it stays there even tho 12.0f are available to scroll down behind it. you can check how far the content is scrolled and if its less than say 0.0f then scroll the scroll view down to 44.0f – j_mcnally Mar 25 '13 at 20:28
  • 1
    I've update my answer with some detail. – j_mcnally Mar 25 '13 at 20:33
  • @j_mcnally You are awsome magician. THank you so much. CGFloat offSet= self.collectionView.contentOffset.y; if (offSet==-32.000000) { self.collectionView.contentOffset=CGPointMake(0, -44); } – Muhammad Nasir Mar 25 '13 at 20:56

4 Answers4

1

The problem here is the scrollview's frame. When the UINavigationBar is translucent the layout is not calculating the height of the navbar so the frame for the scrollview starts at 0,0 rather than 0,44. The solution is to do what you already did, but change the content inset to offset your grid.

enter image description here

Change the top content inset to reflect the size of your navbar. This will allow your content to scroll under the navbar without it starting under the navbar. You may need to turn off auto layout on the view to get this menu option. I personally don't use autolayout because it breaks 5.x compatibility.

If this leaves too much space on rotation you should adjust the inset in your shouldAutorotate function or you can subscribe to the rotation events in NSNotificationCenter.

Per your new issue, it would seem that even though you are increasing the offset, your view has moved to 32.0f from the top, when you rotate and change the inset to 44.0f its not resetting the scrollviews content offset. So your at 12.0f, even though scrolling down would move you to the proper position 0.0f.

So you can have it reset the contentoffset to 0.0 every time you rotate or only if the view is scrolled just partially under the view like in your example. so if the contentOffset is < 44.0f then just set it to 0.0 if its greater leave it alone. Or you can recalculate a new offset +12.0f every time you rotate the view back to portrait, and vice versa to compensate for the difference in inset.

halfer
  • 19,824
  • 17
  • 99
  • 186
j_mcnally
  • 6,928
  • 2
  • 31
  • 46
  • Very nice answer, how ever the contentInset doesn't change if device is rotated. In Landscape mode the device navigation controller is much thinner and i will have a white space under the navigation controller. I know there is a method - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation but upon left and then right rotation the content moves abit to top and this is giving me headaches. please help me if you can. – Muhammad Nasir Mar 25 '13 at 20:11
  • can you update your answer with the roation handling code you have? I dont think there is a great way to do this with out handling the rotation yourself. – j_mcnally Mar 25 '13 at 20:14
  • if Portrait +12.0f else -12.0f, the issue is your lose/gain 12 pixels when you rotate. – j_mcnally Mar 25 '13 at 20:46
  • Thank you So so so so much. You are a magician. Here is how i am doing it. CGFloat offSet= self.collectionView.contentOffset.y; if (offSet==-32.000000) { self.collectionView.contentOffset=CGPointMake(0, -44); } – Muhammad Nasir Mar 25 '13 at 20:55
  • Its Working Perfectly Now. – Muhammad Nasir Mar 25 '13 at 20:55
0

I have already tried adding section header to collection view but the problem with that is upon device rotation the size of header remains same.

You could check the current device orientation in tableView:heightForHeaderInSection: and return a different height based on the current orientation.

Community
  • 1
  • 1
bdesham
  • 15,430
  • 13
  • 79
  • 123
  • I used if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) { NSLog(@"Is in portrait Mode"); //self.collectionView.contentInset=UIEdgeInsetsMake(44.0f, 0.0f, 0.0f, 0.0f); //self.collectionView.scrollIndicatorInsets=UIEdgeInsetsMake(45.0f, 0.0f, 0.0f, 0.0f); and adjusted the inset but upon left and then right rotation the content moves a little inside the navigation bar i dont know why its happening. – Muhammad Nasir Mar 25 '13 at 20:15
  • 1
    That's happening because iOS thinks that the content has been scrolled. You could write a special case for when the UIScrollView is scrolled to the top, and keep the view scrolled to the top after any rotations. – bdesham Mar 25 '13 at 20:39
0

you may be able to take the black and adjust alpha properties.

self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBar.alpha = 0.2f;
apollosoftware.org
  • 12,161
  • 4
  • 48
  • 69
-1

I would do a viewcontroller and add a collection table to it. Then you can resize to whatever you need. You probably used the collectionViewController template so now you have less control.

Once you do this, place the collection table under the nav bar.

William Falcon
  • 9,813
  • 14
  • 67
  • 110