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

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

Related

Scrollview vertical only with fixed width in Autolayout

In swift how can I set the width of the scroll view to be the width of the screen size?
I tried setting right leading and trailing bounds, but my aspectscalefill image keeps stretching the entire frame.
I am trying to force the view to be the width of the screen and allow vertical scrolling only.
If you want to make a scroll view with auto layout try this. No code at all so you will have to drag things out of the library to the right of Xcode.
In your view controller drag and place the scroll view size it to whatever you want but it looks like you want to make it the size of the screen. Pin all edges to the edges of the view controller. Pin trailing, leading, top, and bottom.
Now, instead of placing your items in the scroll view, place another view in the scroll view. With this new view you will place all of your items. You will most likely have to move the view up or down to place them all and resize the view. You can then place whatever constraints you want on your items. When all items are in their place, set the frame of the new view back to x = 0 and y = 0.
You will then place constraints as follows. Select the new view and pin to top, bottom, trailing, and leading and then center in container. This will make a constraint that is vertical with some negative number. In the storyboard outline select this constraint and set it to zero.
You will now be able to scroll vertically. Let me know if you have any questions.
I created a single view application, and added a UIScrollView in the storyboard with four constraints (top, left, right, bottom). And I add the following code in the viewDidLoad(). Everything works just fine. My image is only scrolling vertically, but not horizontally. No additional settings are needed.
#IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Just as an example, I make a size with same with of the view
// and twice the height of the view.
let size = CGSizeMake(
self.view.frame.size.width,
self.view.frame.size.height * 2);
// Load an image and make a image view
let image = UIImage(named: "im.jpg")!
let imageView = UIImageView(image: image)
imageView.frame = CGRect(
origin: CGPoint(x: 0, y: 0),
size: size);
imageView.contentMode = UIViewContentMode.ScaleToFill;
// Add the image view to scroll view
scrollView.addSubview(imageView)
scrollView.contentSize = size;
}
Your problem i caused by the fact that you add your elements to the scrollView from the storyBoard.
In the storyBoard you need:
1) Add the scrollView, if you need to be in the width of the screen then set it's trailing and leading spaces to superView to 0
2) uncheck the "allow horizontal scrolling" in the attribute inspector
In your code
1) set the scrollView's contentSize to what ever size you want it to be.
1.1) in your code you need to set the size of the contentView like so
scroller.contentSize = CGSizeMake(your width, your height);
This is a very important step, the scrollView will not be able to scroll if you don't set the size. Think about the scrollView as the window and the contentView as the view. If the contentView if the same size as the scrollView then the scrollView can't scroll anywhere (all of the contentView fits into the scrollView) in order to create the scrolling you need to make the contentView bigger then the scrollView itself
2) start adding your elements to the scrollView's contentView by calling
[scroller addSubView:<your view>];
this will add your views to the scrollView's contentView and will be

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!

DIsplay a view in front of a UITableView with Auto Layout

Below is what I am setting up for my view. There is a mask (UIView) with bottom space to superview of 0.
When I am displaying on the simulator (iphone-retina 4) or on a device(iphone 5) ,the mask is disappearing.However, there is no problem with simulator (iphone or iphone 3.5 ) or device(iphone4)
Should 'bottom space to superview = 0' not let the mask off screen ?
The Auto Layout constraints are fine. The mask won't be displaying because the color is [UIColor clearColor], the alpha property is 0.f, the 'hidden' property is set to 'YES', or some other reason such as the view being removed from it's superview parent.

Difficulties Re-positioning TableView in Xcode

I have an application in Xcode 4.5.2 that uses storyboards. I have a table view, and I want to reposition the table view so that it is a bit lower on the screen so that I can add an image and a button above where the table view starts. I have researched this question and although I have found a couple of suggestions, none have worked for me yet. The table view is accessed via a modal segue, so there is no navigation bar.
Here is what I have already tried:
1) I added a navigation bar and set its background to my image and then tried to add the button into the nav bar. Because Xcode would not let me resize the nav bar, my image was distorted as was my button and so I abandoned this effort.
2) I added a tool bar but had similar issues as I did with the navigation bar.
3) I attempted in code to move the table view down (thinking I could add the image and button in the free space above the table view). This did not work at all, my table view origin remains at the very top of the screen. but here is the code:
//called in the view did load method of the table view controller class
- (void)repositionTableView
{
float yOffset = 75.0;
CGFloat x = self.tableView.frame.origin.x;
CGFloat y = self.tableView.frame.origin.y + yOffset;
CGFloat height = self.tableView.frame.size.height;
CGFloat width = self.tableView.frame.size.width;
CGRect newTableFrame = CGRectMake(x, y, height, width);
self.tableView.frame = newTableFrame;
}
Can anyone give me any suggestions on how to approach this problem? Thanks.
Make sure:
You created a UIViewController.
UITableView is the subview of self.view.
Autolayout is disabled.
And you can move it freely.

Stop UIToolbar from Disappearing in Landscape Orientation - iPad

Not sure why this happens or how to stop it, my UIToolBar on the details viewcontroller is only visible during portrait view. I want it visible at all orientations. How do I do that? Thank you.
I encountered the same problem by just dragging a UIToolBar on to my view and docking it on the top of the window. It showed up in landscape but not portrait. Interface Builder - at least the one embedded in Xcode 4 - doesn't seem to do the right thing with the resize masks.
While Kshitiz's answer above will work, it has a couple of flaws. As coded, it does not support all four orientations. More importantly, it's not resolution independent.
A better solution is briefly described in enamrik's comment, so credit should go to him/her. Here are the steps:
Select the tool bar in Interface Builder.
Open the Size inspector.
In the Autosizing box, select the left, right and top "i-beams" on the exterior of the square. This keeps the position of the toolbar fixed relative to the sides of the view when the view is resized.
Inside the Autosizing square, select the horizontal line with arrows on both ends. This causes the size of the toolbar to change in sync with the parent view.
in your this function of view controller reset view frame bro
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
self.view.frame = CGRectMake(0, 0, 703,768);
} else {
self.view.frame = CGRectMake(0, 0, 768, 1024);
}
return YES;
}
and your tool bar frame too
good luck
Faced the same problem when I add UIPickerView programmatically and add UIToolBar for the PickerView. Just need to add [.flexibleWidth,.flexibleHeight] for the UIPickerView. eg:-
let statTypePicker = UIPickerView()
And then add
self.statTypePicker.autoresizingMask = [.flexibleWidth,.flexibleHeight]