When I run the application on Xcode an error appears saying "Modal segues are deprecated in iOS 8.0 and later". When I get to the simulator everything appears very large even after I reduce the scale to 50%.
There seems to be two questions here.
1) Why are Modal Segues deprecated in iOS8 and should I be concerned?
and
2) Everything is big in the simulator.
Modal Segues are replaced with adaptive segues in iOS8. The View Controller Programming Guide has information on the replacements, such as the "Show" segue and the "Show Detail" segue. The idea is that you can use one storyboard to describe an interface that works well on iPhones with small (4S, 5) screens as well as larger screens (6, 6+) and even iPads. To make efficient use of larger screens, it's now possible to have split views on iPhone in iOS8, and the new segue types let you specify that the next view should be shown in the detail area of a split view, or in the current view controller's area (aka its "context").
Traditional modal segues will continue to work, but they are not the preferred approach any longer, and as with all deprecated API, there is a possibility that a future release of the OS may remove those deprecated features. Consider revising your app to use the new approach. There are some WWDC videos, #214 and #218 at https://developer.apple.com/videos/wwdc/2014/ that are worth a watch if you want to get up to speed in a couple hours.
As for things being bigger in the simulator, it sounds like you're using the iPhone 6+ simulator, which is not only larger but also has 3X the pixels of a traditional iPhone non-retina. It will be larger when you run it, so you might want to drop it down to a smaller size like 50 or 25%. As an extra tip, those "change the size" shortcuts are Command+1, COmmand+2 and Command+3, so it's pretty easy to shuffle the size around. Alternatively, use another simulator, like the 5S Simulator.
Related
I don't know if this is a bug with AutoLayout or Xcode but I've realised that if I run my application on a device which isn't the same size as the device in my storyboard, the elements are adopting the incorrect size.
I.e. Selecting View as iPhone SE and running the application on an iPhone 7+ The size of my tableview is the width of an iPhone SE screen, this fixes itself when I reload the view and then it then adopts the width of the iPhone 7+ screen.
Just a note as well the table view doesn't have a fixed width and is pinned to the top, bottom, left and right with 0 spacing and also I'm changing the height of the cells programmatically in code if this could affect it at all as well.
Video: https://drive.google.com/open?id=0B0QLbDLfJn6_YzljUGg4RTUwaTg
Views that come from a xib (or storyboard) have their IB frame values when they are created, before they are added to the view hierarchy. So a case like you describe is probably that something is accessing a view loaded from a xib before it has become part of the layout process and resized.
This would also explain why it's fixed when you go away and come back. The first time, it got the values before they were final, but the second time the values are already final and correct.
Layout code called fromviewDidLoad() for view controllers, or awakeFromNib() or initWith(coder:) for views is the likely cause. Layout code called from viewDidLoad() is especially problematic because it was fine up to iPhone 5s, but would now cause this problem.
It's impossible to say what exactly the issue just from this. From the NSLog statements visible in the video, the issue is whatever code calls that "weather view width". That is being called too early in the layout process. It needs to go in viewWillAppear or viewWillLayoutSubviews to make sure the correct values are ready for whatever calculation is dependent on that. Hope this helps.
I can't seem to recreate this. I would recommend double checking for any updates for Xcode and the Developer tools (softwareupdate --install -a).
Incase you haven't, restart Xcode.
EDIT: Disregard this answer, please read Mike Sand's post.
Try self.view.layoutIfNeeded in viewDidLoad or in viewWillAppear
Good morning,
I am new to Xcode and am learning to create iOS applications.
When I open a single view application and click on main.storyboard, my size is w Any h Any. When I decide to add a label and run the iOS simulator (iPhone 6 or iPhone 5S), the label appears somewhere else.
This is really frustrating and I have tried many approaches such as disabling use size classes, changing the storyboard size by clicking the w Any h Any button, and even messing with the constraints as mentioned here: Xcode 6 Storyboard the wrong size?
I am really trying to continue with this but I have seem to hit a wall for a couple of hours now, if someone could shed some light to why I am messing this up, that would be amazing.
EDIT: How can I get it to be a "normal" sized iPhone, such as the iPhone 5s?
You can click on the w Any h Any to change it to a normal iphone size by mousing over the squares and reading which devices they encompass.
You are going to have to use constraints though in order to make anything go where you want it to, I really didn't want to learn them but I couldn't do without them now: they are very useful.
EDIT
Constraints are simple in concept but can be tricky in certain situations:
For any view to have valid constraints that work correctly, it needs to know what the size of the view is and its position in it's "parent container" which is just whatever view or viewController it is inside of.
The little |-O-| shaped button and its neighboring buttons next to "w Any h Any" give you options for positioning and sizing the view. So if you click on a view and then click on that square button in the middle, check the width, height boxes and click the left and top lines in that top positioning thing with sizes in it like so:
Then click on add 4 constraints. You will notice blue lines appear around your view saying that it can properly put it where it needs to go when running the app. If there is any orange or red that means there are conflicting constraints on the view.
Sometimes that can mean you put to many constraints (more than you need) and you just need to delete them in size inspector tab. But more often than not, if that doesn't fix it, I've noticed that I usually have a neighboring view that isn't properly "constrained" and is actually the cause for the other views problems.
How can I get it to be a "normal" sized iPhone, such as the iPhone 5s
You don't. The view controller's main view will be resized correctly when the app runs (on a device or in the simulator), as appropriate for the device type and other aspects of its surroundings.
Your job is to use auto layout so that no matter how the view is resized, its subviews (labels and buttons and so forth) will look good. That is what auto layout is for - it's to help you compensate for the fact that you have no idea what the real size of this view will be at runtime.
I need to take a screenshot of whole storyboard as an image. Is that possible? I need it to give to my designer.
Ideally I'd like to get 1 big image, make some changes (number views, etc) and save it as JPG
Xcode doesn't have any features for printing or exporting an image of your storyboard. (Though that might make a good feature request to send to Apple.)
Your best bet is to resize your project window as large as possible (and hide the navigator and utility sidebars) and take a screenshot. You might be able to employ a trick or two in getting everything to fit:
If you're on a Mac with a Retina Display, change your screen resolution to one of the "more space" options so your Xcode window can be bigger. (For example, on a 5K iMac you can choose the "looks like 3200 x 1800" size, which renders a 6400 x 3600 screen and downscales it to fit the actual display hardware.)
Zoom out on the storyboard with the Editor > Canvas > Zoom menu commands. In Xcode 8, the zoomed-out storyboard uses the same rendering/editing engine as the regular-size view — which means that on a Retina display, your shrunken-down views will still be legible.
Resize the window larger than the screen, then take a window screenshot (Cmd-Shift-4, then spacebar, then click the window). You can do this with AppleScript:
tell application "Xcode" to set bounds of front window to {0, 0, 4000, 3000}
But that'll still limit its height to that of the screen (minus menubar and Dock). You can drag the window to the bottom of the screen and edge-resize it upward to get some extra height, though.
One more thing: Since the beginning of storyboards (way back in Xcode... 5, I think?), you've never needed to have "one storyboard to rule them all" in your project. In fact, there are lots of reasons why it might make sense to break your app into multiple storyboards. And of course, if you have multiple storyboards, you can screenshot them separately and integrate them however you like for a design presentation.
Using multiple storyboards used to mean you couldn't segue between view controllers in separate storyboards (you'd have to instantiate and present view controllers programmatically), but since Xcode 7 you can insert a "Storyboard Reference" in one storyboard to link to a view controller in a different storyboard. And if you have a big storyboard you want to break up, there's a tool for that. (Select some view controllers, choose Editor > Refactor to Storyboard...)
I am hoping someone can help me out with this one. I have an app that I am trying to update to get rid of the letterbox look when running on iPhone 5. I have added a Default-568h#2x.png to the project and the application seems to scale correctly. The splash screen on either device looks correct, however I have a toolbar on my "Home" screen that I can't seem to get in the right place. If I get it right for 5, I can't see it on 4s, and if I get it right for 4s, it is very low on 5.
Am I missing something? Do I need to manually move the toolbar that is at the top? And will I need to move all the controls around on all of the screens in the app?
Any advice is appreciated!
Thanks
Here are some tips on using Interface Builder to handle resizing.
Take advantage of the Simulated Metrics in Interface Builder, as shown here:
To do so, select your top-level View, and open the Attribute Inspector. Then, you can select different sizes and orientations to see how your view responds.
Select the Autosizing options as shown here:
In your case, you want a fixed margin above, but a flexible margin below. Note that this is the opposite of the default for a toolbar because the iOS convention is for toolbars to be at the bottom of the view.
Realize that resizing due to rotation and different screen sizes can often be handled the same way. (Thus, if you handle portrait and landscape orientations using Autosizing, iPhone5 layout usually takes care of itself.)
In a .xib file how do I keep the Autolayout on for iOS 6 but off for iOS below 6.
If I turn it off my .xib doesn't get the proper layout . If I turn it on my Iphone with 4.3 crashes.
Any help would be appreciat it
Thank you
I don't believe this is possible as autolayout changes how your application is compiled. The options I've considered for a workaround to this are:
Detect the height of the display and programmatically change some of the elements (ick, but I've done this when it was just a simple change)
Detect the height of the display and programmatically load the appropriate nib (the downside is maintaining two nibs)
Ignore 4" displays and submit with black borders (let's assume no one should want this)
Attempt to design layouts that won't suffer from having some additional space. (This is always desirable, but not always possible. UIScrollViews/UITableViews are definitely good with this, but not fixed full-screen views.)
I am still looking for better solutions myself.
Here is the code I use to determine 4" vs 3.5" iphone:
if (screenBounds.size.height == 568) {
// code for 4-inch screen
} else {
// code for 3.5-inch screen
}
Even this seems hackish, but talk to Apple about that. :|