iPhone app's storyboard does not display correctly on iPad - ios

I've spent a lot of time attempt to research this issue and haven't gotten any results unfortunately.
[edit: being more explicit with my question]
My question is: why are the objects on my view controller not appearing when I run the iPad simulator? The background color of the view controller is displayed. The navigation tab bar appears as well. But neither of the two objects on my view controller appear (which have constraints on them).
[/edit]
If I look at the info.plist I see that I have "Main Storyboard file base name" with a value of Main (which makes sense, as my one and only storyboard is main.storyboard).
When I run the app within the iPhone simulator, all is well. When I changed the simulator to iPad, this is what happens:
Launch Screen appears
View Controller appears with the background color I have chosen in my storyboard scene.
When in debug, I see that it's going through the code to load up my views as it does when running in the iPhone simulator.
The Tab Bar controller's tab bar appears at the bottom of the view controller as expected.
Is this somehow related to the width and height I have selected? I have it set to: wCompact hAny. When I change it to wAny hRegular, the items I had placed in the scene (a UIView and a UITextField) "disappear."
Some background:
I originally created the app as Universal. But what I want, at least for now because I'm still learning, is just an iPhone app that will also run on an iPad (with that 2x option). I changed the Targeted Device Family to iPhone under both the Target and then later under Project.
I know one option is to just make an iPad layout, but I'd really like to know what I'm doing wrong here.
[edit: one solution]
The resolution I took, although I feel it's not the one I wanted, was to change the size to one that iPad supports and then paste the two objects (UIView & UITextView) into the scene that was defined as wAny hRegular. Then I hooked up those 2 objects to their outlets in the View Controller and I now have my app appearing in the iPad simulator.

Related

ios UI is not scalable for my storyboard

I'm new to ios.
I have created a storyboard. I gave it's view size and location.
I intended it be scalable, so I used ration size and relative spacing.
However when I run the ios simulator I see the storyboard very different on iphone 6S and iphone 5 for example.
Here is my mock:
Here is my source-code
iphone 4s simulator:
iphone 5s simulator:
what can i do to make it scale right?
You need to use Auto Layout. While in your storyboard, click your ViewController and then go to the attributes inspector (in the pane on the right side of Xcode, the "attributes inspector" is the tab that looks like a down arrow), and for "size" make sure "inferred" is selected. If it is not selected, then click the drop down menu and select it. Then when you are placing objects on the view controller scene, you must add the appropriate constraints at times to ensure that everything gets scaled properly on different screen sizes. Read here https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html

iOS Launch screen code not running

I heard about the new feature which xcode 6 brings, that allows you to make a storyboard as a launchscreen.
Now..
Is there a way to control UI elements on the launchscreen story board via a viewcontroller?
(to show a loading screen or something)
I tried it, I simply did a println("Here's the view loaded on the loadingscreen") in the viewdidload on the controller which is referred to the view in the launchscreen story board, but there's no output at all..
What am I doing wrong?
You're not doing anything wrong.
No code is associated with the launch screen. You can't run any logic. It is purely there so that you can use AutoLayout to layout the launch screens for different sizes of device.
You can't specify any class to launch screen and run code there. The storyboard file is only an alternative for multiple splash screens (Launch images). You can use a single storyboard/xib file based launch screen for different iOS platforms and orientations (You can handle that using Auto Layout).
The major point that you need to remember is, at that point the application is not completely launched.
So viewDidLoad or any view life cycle methods will not be invoked.

UIButton size appears as DEFAULT at runtime despite being resized in XIB

I have a iPhone app I am converting to Universal. I properly set up the MainWindow-iPad.xib and tied its view controller to my view controller class and all the other links etc and at run time, under the iPad simulator the App WORKS Perfectly...
However, I have 2 buttons in the XIB for iPad, and while in the XIB they are both resized from the default size to the sizes I want, and appear properly, at runtime under IPAD they appear as though the are still the default size when added to the XIB.
All other things done to the buttons appear proper, images, text, backgrounds etc are all working perfectly fine, but for some reason on the IPAD and IPAD Emulator only they are ignoring the size the XIB says they should be.
Does anyone have any idea what is going on? I have double and triple checked all the settings for the buttons in the XIB editor to ensure there is nothing different between the IPAD and IPHONE xib files related to these UIButtons, but they still appear at runtime with the wrong size.
Okay, DOH! moment... had an explicit XIB load in the code... so it was always loading the default MainWindow.xib no matter what...

Xcode storyboard: Why does the iPad storyboard show iPhone sized views?

I have a universal app that uses storyboards. There is an iPhone storyboard and an iPad storyboard. However, in interface builder, the viewcontrollers for the iPad storyboard are still sized for the iPhone. How do I get the iPad storyboard to show iPad sized view controllers?
I realize that the view controller display in interface builder is design-time-only eye-candy, but having iPhone sized VCs makes it really hard to lay out the UI correctly.
After some digging through the storyboard source code, it turns out that the iPad storyboard was copied from the iPhone storyboard. So, the question really became how do I convert an iPhone storyboard into an iPad storyboard?
The answer is surprisingly simple. I ran across this SO answer -- to convert an iPhone storyboard to an iPad storyboard, do the following:
From Xcode, right-click on the storyboard and choose Open As ->
Source code
Search for targetRuntime="iOS.CocoaTouch"and change it to targetRuntime="iOS.CocoaTouch.iPad"
Right-click on the storyboard again and choose Open As -> iOS Storyboard
The storyboard will now show all views in the correct size.
When you first create a storyboard you select a Device Family (iPhone or iPad) that the storyboard is targeted for. I don't know of a way to change the device family once the storyboard has already been created.
However, to solve your problem I recommend the following:
Create a new storyboard by going to: New -> File -> User Interface -> Storyboard (Be sure to select Device Family = iPad when choosing the options.)
Go to your old storyboard, select and copy everything by pressing Command-A, Command-C. Then go to your and paste everything by pressing Command-V. Your view controllers will now be iPad-sized.
You can then delete the old storyboard and rename your new storyboard to whatever the old name was.
This answer is not a solution, but will help to get one of the reasons why such things happen.
The issue occurs when you try to disable:
"Use Auto Layout"
When you uncheck it, the popup window appears. There is select:
"Keep size class data for: iPhone", by default is selected iPhone (no matter which iPad or iPhone project you created).
If you will not mention on it, your storyboard will be auto converted to iPhone sizes.
Do not forget to choose right device.
I used the suggested answer to convert an iPhone storyboard to an iPad storyboard and it worked great for most of my views. However, I realized that one of the views was still iPhone storyboard sized. The reason was because I had locked All Properties of one background image (because I did not want to accidentally move it). Removing the lock turned the view back into iPad sized. This might help someone stuck on this.
Make sure you set the right Storyboard in Target > General. This kinda stuff makes me headache for 3 hours before i realise i set the same storyboard for iPhone as my iPad storyboard.
In my universal app, I was using SpriteKit for the main viewcontroller. The SKScene.scaleMode was set to aspectFill. When run in the iPad simulator, the app started up iPhone mode. Solution was to set scaleMode = .resizeFill.
For me i have found it more easy by changing the view controller presentation to Full Screen rather than Automatic, I use Xcode 12.1

Xcode View Controller - Horizontal orientation issue

I have got two view controllers on a Storyboard in Xcode. If I Build and run the application with the initial View controller set as the startup item (The app only allows horizontal orientation) then the application in the Simulator is displayed correctly with all the images in the correct place in Horizontal orientation.
However if I add another View controller to the Storyboard (setting this as the startup item). The simulator is run and displayed horizontally however the graphics are being displayed as if the screen is in vertical orientation.
The plist looks correct and also I have tried setting up the simulated metrics to Landscape and Full Screen. However this does not seem to have worked. The display looks correct within Xcode. It is just when I come to run it on the simulator.
I have searched across Google and have come across articles on Rotating iPads and Orientations.
Can anyone help with my issue? Do I need to add any extra code to get my new view controller to be recognised in the horizontal orientation? or is this a bug with simluator?
Thanks
I have found out the answer to the question myself and I thought I would share.
All I needed to do was select the ViewController Class in the Utilities Screen.
I assume by doing this it can invoke the shouldAutorotateToInterfaceOrientation method and also know which way around the screen should be.

Resources