Hiding Nav Bar moves view "up" - ios7

The usual story -- I'm making an iOS 5/6 app run under iOS 7 and the navigation bar behavior change is causing a problem.
The app already worked like the iOS 7 default with a full-screen view and a translucent nav bar "over" of the view. The problem is that hiding/un-hiding the nav bar causes different behavior in iOS 7. On iOS 5/6 hiding/un-hiding the nav bar does not change the view. On iOS 7, hiding the bar visually moves the view up leaving a blank bar at the bottom of the screen and un-hiding the bar moves the view back down to occupy the full screen (with the nav bar on top, of course).
I need to continue to support iOS 5 so I don't use auto layout, but I do use the full screen.
I have a view in which I'm viewing a zoomable image -- so the view controller has a fullscreen view containing a scrollView which contains an imageView.
The status bar is always hidden.
I get to the view controller via a navigation controller so there is a (black, translucent) navigation bar which lies over the top of my fullscreen view/scrollView/imageView.
After a brief delay some overlaying labels fade and the navigation bar is hidden
A single tap restores the overlay labels and un-hides the navigation bar.
This works on iOS 5/6 -- the navigation bar slides off the top of the screen uncovering the top of the view/image.
On iOS 7, when the navigation bar slides off the top of the screen the entire view visually moves up a corresponding amount (i.e. 44 points) leaving a black bar at the bottom of the screen. I can see this by setting a background color on the top-level view and resizing the scrollview enough to see the background; the top of the view does indeed move offscreen and the background color is not drawn over the bottom (44 points) of the screen.
BUT, self.view.frame doesn't change and remains at {0, 0} 320 x height.
When I single-tap to restore the overlay info and navigation bar the view moves back down to occupy the full screen and the translucent nav bar is over the top of the view/image.
Nothing I've tried changes the behavior:
Changing the IB view controller layout controls (Under top bars, Under bottom bars, Adjust scroll view insets). Building for 5.1, 6.1, and 7.0 all produce the same result when run under 7.0.
self.edgesForExtendedLayout = UIRectEdgeNone
does nothing. Using the layout delta values doesn't do anything. In IB the view looks the same when "viewed as" iOS 7 and iOS 6 and earlier. I print out a lot of debug info but nothing about the view (or scroll view) seems to change when the view moves "off screen".
The code that shows the overlay info (run when the view is first shown and on single-taps) is:
- (void) showOverlayInfo {
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
[[[self navigationController] navigationBar] setTranslucent:YES];
[[self navigationController] setNavigationBarHidden:NO animated:NO];
overlayInfoHidden = NO;
overlayInfoFading = NO;
self.infoButton.hidden = NO;
self.infoButton.alpha = 1;
self.descriptionLabel.hidden = NO;
self.descriptionLabel.alpha = 1;
}
The code that hides the overlay info is:
- (void) hideOverlayInfo {
overlayInfoHidden = YES;
overlayInfoFading = NO;
self.infoButton.hidden = YES;
self.descriptionLabel.hidden = YES;
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
So can anybody tell me what (presumably simple) thing I'm missing?

I finally found my problem.
The key fact is that the image-viewer view controller was in a UIPageViewController,
so what I was looking at and experimenting with was really "inside" another view controller.
Although I had disabled the view controller setting Adjust Scroll View Insets for the image viewer VC, I hadn't done it for the containing VC that created the UIPageViewController and the UIPageViewController presents the pages in some subclass of a UIScrollView. When I changed them for the parent VC, the problem vanished.
So I think the moral of the story is to:
Think about the problem more globally when local doesn't work because maybe you're missing some important context.
If you don't want to use the iOS 7 behavior, change the settings for every single view controller you have!

Related

iOS 8 - Modal in Popover

I have a popover with TabBarController in it. In one tab there is a TableViewController with a list of names. And there is a plus button, that has a modal segue to AddCharacterVC for adding new names.
In iOS 7 I do it like this:
AddCharacterViewController *acvc = (AddCharacterViewController *)segue.destinationViewController;
acvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
acvc.modalPresentationStyle = UIModalPresentationCurrentContext;// so it does not take full screen in popover
And in AddCharacterVC I set content size like this:
- (void)viewWillAppear:(BOOL)animated {
CGSize size = CGSizeMake(320, 480); // size of view in popover
if (IDIOM == IPAD && [self respondsToSelector:#selector(preferredContentSize)]){
self.preferredContentSize = size;
}
And it works perfectly.
However, in iOS 8 modal view does not cover the whole popover, leaving TabBar visible. The user can tap on it or not, anyway modal view won't unwind properly.
I've tried:
setting acvc.modalPresentationStyle to UIModalPresentationOverCurrentContext
tried to set TabBar hidden
checked in storyboard that edges of TableVC extend under Bottom Bar and Bottom Bar in Modal View (AddCharacterVC) is set to none
All with no results.
Now the only thing I can think of is to try making modalPresentationStyleCustom and use UIPresentationController (I'm trying to do it now, but I haven't done it before). Am I missing something? Could there be other way to do it? Sorry, I cannot post images here yet. Many thanks in advance!
Ok, so I've set the modalPresentationStile to UIModalPresentationCustom, and used UIPresentationController - I've just copied code from WWDC-14's LookInside project and modified it a bit.
I'm not sure if it was the best solution, but it worked in my case.

iOS 7 tab bar shown in wrong position

iOS 7, the tab bar does not appear in the bottom of the screen.
I am just using a Tab Bar Controller in my StoryBoard.
Update: I tried to set is location at the top of the screen programmatically (code below), it was correctly positioned there (at the top)
UITabBar* tabBar = self.tabBarController.tabBar;
tabBar.frame = CGRectMake(0, 0,
tabBar.frame.size.width,
tabBar.frame.size.height);
But when I tried to set it at the bottom (code below) the bar totally disappeared!
UITabBar* tabBar = self.tabBarController.tabBar;
tabBar.frame = CGRectMake(0, self.view.frame.size.height - tabBar.frame.size.height,
tabBar.frame.size.width,
tabBar.frame.size.height);
Any help?
Thanks.
I know I should not answer my question but the solution is actually simple (After 1.5 hours of headache):
My tab view was part of a bigger project that already had a navigation controller that includes a tabBar. So all what i did is hiding this original tabBar so that mine can take its position.
Just this line:
self.navigationController.toolbarHidden = YES;

iOS 7 Navigation Bar and Scroll View are different in storyboard and simulator

I have a navigation controller with navigation bar, not translucent. I added a scroll view to the root view. But when I run the app, it show different from what I saw in StoryBoard. Everything shifted down.
This is what I saw in StoryBoard:
This is in simulator:
Your storyboard should like this
In ios 7 scroll view must be covered to entire screen
You need to put image on top edge
You will output as below
make a full screen UIScrollView, add a full screen Content View to UIScrollView
add a transparent view to top of this Content View: top:0, left: 0, right: 0, equal width with scroll, height: 64(height of status bar & navigation bar)
hook up Transparent View's height constraint (which is 64) to your ViewController Class as a IBOutlet:
design your view as you wish; I will add a button below the navigation bar: top space to transparent view: 8, left: 8, width: 30, height: 30
add code below to your ViewController Class; if the iOS version is iOS7, set Transparent View's Height Constraint to 0(zero), if it is iOS8, do nothing:
- (void) updateViewConstraints {
[super updateViewConstraints];
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
_transparentTopViewYConstraint.constant = 0;
}
}
as a result, all your view's top space is relative to Transparent View, if system version is iOS7, your Transparent View's height will be 0(zero) and your views are move to top, top space will be just 8 for my example, so your views place just below the navigation bar. if system version is iOS8, your Transparent View's height will be 64 and your view's top space will be 8 + 64, so your views place just below the navigation bar again.
please check the following:
is auto layout on? then turn it off
Are you using a simulator of different size? (story board is for 4 inch, while simulator is 3.5 inch) if that so, many things are to set up like turning off autoSizing right and bottom constraints
Hope this helps

Present UIView modally that nots full screen

I have a view 200 x 150 px which i would like to present on the tap of a button. If i use addSubview: then the view shows up in the correct position, but i can still tap other buttons on the superview, which is behaviour i don't want.
If i use presentModalViewController then the view takes up the whole screen, which is what i don't want either... this happens even if i set wantsFullScreenLayout to NO.
How can i present the view so that the user can only interact with controls on the presented view?
Thanks
Make the view the size of the screen (taking the status bar into account). That view should have a translucent background color (or clear). Have the 200x150 view be on the bottom of that view to have the appearance of a UIActionSheet, where the background dims and the user cannot interact with other elements on the screen.
Then, you can use presentModalViewController to present the view.
Addition
In the view controller's .m file, define awakeFromNib:
-(void)awakeFromNib
{
self.view.backgroundColor = [UIColor clearColor];
}

Fullscreen UIView with Status bar and Navigation Bar overlay on the top

What is the proper way to implement the status bar and navigation bar that go on top of an UIView?
alt text http://img.skitch.com/20081217-t78sdixk37hqgdh1ia2fgec4st.png
Just set “wants fullscreen layout” in your view controller. That solves the problem for me.
self.wantsFullScreenLayout = YES;
In the screenshot above, there's a translucent status bar and a translucent navigation bar.
The status bar is set using
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
The navigation bar is set using
theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
If you have a view controller inside a navigation controller, and you want to hide the status bar in order to have your viewController's view in full screen, you can always call :
[self.navigationController.view setNeedsLayout];
after hiding the status bar.
But I personally think
[self setWantsFullScreenLayout:YES];
is a better way.
The best way I came up was this: when using a "complex" hierarchy of Tab bar containing navigation controllers, with one "detail" view being a full screen view.
In the app delegate just before the tab bar controller's view is added to the window, I added this:
tabBarController.view.frame = [[UIScreen mainScreen] bounds];
This will make the tab bar controller cover the entire screen, even below the area of the status bar. I had to offset heights of several views to +20px, notably the navigation bars.
Set the statusbar style as black translucent and navigation bar style as black translucent. If you are using a navigation-based application, in the MainWindow.xib check the status bar is hidden and navigation bar is hidden checkboxes.
When the user touches the screen, start a timer to see if this was a single tap or double tap. If a single tap, make the statusbar and navbar hidden = NO. and once user activity stops, start a timer again. after some time of no activity, make them hidden again.
step 1 Set the UIViewControllerBasedStatusBarAppearance to No in the plist
Then add the following code in did finish launch option
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
Please follow this code it worked for me