navigationBarHidden false => true brings problems with toplayoutguide on iOS 7 - ios7

for one ViewController in my navigation stack I'm hiding the navigationBar (navigationBarHidden = true in viewWillAppear: and navigationBarHidden = false in viewWillDisappear:).
After that, the topLayoutGuide is moved up by 40 pixels, if I animate a view to toplayoutguide = 0, the view is out of sight.
This only happens on iOS 7 - how can I prevent this?

Related

UIPopoverPresentationController has wrong anchor position on iPhone 6 plus and 7 plus when it's in landscape mode [duplicate]

In my iOS 8 app, this popover segue appears correctly on all devices in all orientations except for iPhone 6 Plus landscape:
This is how it looks on iPhone 6 Plus landscape (it is stretching almost from top to bottom):
And when it displays like this, clicking outside of the view doesn't dismiss it (although Cancel does work). Rotating back to portrait gets it back to normal.
All of the constraints in this UIViewController are installed on all size classes.
When debugging values in viewDidAppear: I see the following:
po self.view: frame = (0 0; 250 394)
po self.preferredContentSize (width = 250, height = 160)
What is causing the view's height to jump to 394?
I'm actually having the same issue with another popover segue in iPhone 6 Plus landscape as well. (And in case there was curiosity, I'm using a VC instead of 'UIAlertController' here because of the validation requirements of the UITextField displayed don't work well with UIAlertController.)
Edit to include my popover code:
This code is found in prepareForSegue:
FavoriteNameViewController *nameVC = segue.destinationViewController;
UIPopoverPresentationController *popPC = nameVC.popoverPresentationController;
popPC.delegate = self;
nameVC.delegate = self;
nameVC.view.center = self.originalContentView.center;
And then the delegate method:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
And here is the segue definition in Xcode:
What you're seeing is not a popover. It's a normal presented view. By default, a popover appears as a popover on iPad, but as a presented view on iPhone — including the iPhone 6 plus. On other iPhones, this presented view is fullscreen - it covers everything. But the iPhone 6 is so wide that they don't do that, so it appears in the middle of the screen at a standard width (the width of a smaller iPhone).
Thus, the preferred content size has no effect. This isn't a popover. Presented view controller views are given a standard size, and this one is no exception.
However, you can have the popover appear as a popover on iPhone. To do so:
Set a delegate for the popover view controller's popoverPresentationController before presenting it.
In the delegate, implement adaptivePresentationStyleForPresentationController: and return .None.
However, this is apparently not working on iPhone 6 Plus in landscape mode; the popover is not "adapting". I would describe this as a bug!
EDIT In iOS 9, the problem is solved! Implement the new delegate method adaptivePresentationStyleForPresentationController:traitCollection: to return .None and you'll get a popover under all circumstances, including the iPhone 6 Plus in landscape. Here's a complete working example where the popover is created and summoned in code in response to a button tap:
#IBAction func doButton(sender: AnyObject) {
let vc = MyViewController()
vc.preferredContentSize = CGSizeMake(400,500)
vc.modalPresentationStyle = .Popover
if let pres = vc.presentationController {
pres.delegate = self
}
self.presentViewController(vc, animated: true, completion: nil)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
}
}
func adaptivePresentationStyleForPresentationController(
controller: UIPresentationController,
traitCollection: UITraitCollection)
-> UIModalPresentationStyle {
return .None
}

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

Hiding Nav Bar moves view "up"

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!

iOS 7 UIWebView rotation to landscape orientation add some bar

I have such situation, all screens in my application is in portrait mode, but I have one screen that could be in both orientations. On iOs 6 everything works fine but on iOS 7 when I rotate to landscape I am receive such situation as shown at the bottom. Big black bar at the bottom of screen.:
I want to make full screen and I have try self.edgesForExtendedLayout = UIRectEdgeNone; but it doesn't work for me.
try to remove the flag (use autolayout) in the interface builer document
My problem was with tab bar when I rotate my device, to solve that issue I have implement next code in my category that works with hiding and showing tab bar on rotation:
#implementation UITabBarController (HideBar)
- (void)showTabBar:(BOOL)show
{
UITabBar* tabBar = self.tabBar;
if (show != tabBar.hidden)
return;
UIView* subview = [self.view.subviews objectAtIndex:0];
CGRect frame = subview.frame;
frame.size.height += tabBar.frame.size.height * (show ? -1 : 1);
subview.frame = frame;
tabBar.hidden = !show;
}
I just add next code at the bottom of the method:
if (IOS_7) {
CGRect tabBarFrame = tabBar.frame;
tabBarFrame.size.height = show ? TABBAR_HEIGHT : 0;
tabBar.frame = tabBarFrame;
}