Xcode View Controller - Horizontal orientation issue - ios

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.

Related

Layout issue with iPhone X cropping off the full screen

Below is the output of my application when displayed on an iPhone X, it works perfect with all other iPhone, since they are not full screen with rounded edges.
as you can see the top portion where the time and battery icons are located is not fully filled in?
I am not sure how I can fix this. Should it be in the code or can I do it in the storyboard, I have tried in the storyboard but I have not been successful yet. Does anyone have any idea and/or tips of what I need to adjust in the storyboard to get it fo fill the full screen.
Please note this has the stretchy header, like twitter profile effect, which I still wish to retain.
EDIT
This question may have the answer you are looking for if you wish to extend your view underneath the status bar on an iPhone X.
Original answer
Is the constraint to the top of your view a hard coded value? You should be using the safe areas to attach auto layout constraints so that your app will layout correctly on the iPhone X.
More information on laying out your ViewControllers for the iPhone X can be found here

Why is iOS simulator displaying blank screen when I rotate device?

Getting through some introductory swift and playing with Xcode and I basically just have a page with some color squares, background color etc. Doesn't do anything. Problem is when I compile the code it will run in simulator just fine and show everything perfect, BUT when I rotate the device, everything disappears and it only gives me a blank white screen. Rotating right or left does it. The only view that shows it is the original upright view (for all iPhone devices that I tested on through the simulator).
Xcode 6.1.1 and iOS Simulator 8.1 are being used on my MacBook Air with OSX 10.9.5.
In the App general page, I have already checked under Deployment info that Landscape Right and Left are both checked on. Storyboard is set on Any H and Any W.
I'm not sure what I'm doing wrong and it has been pretty difficult searching since I'm still new to iOS development I'm not sure I'm using the right words or whatever because I can't find an answer.
Summary:
App displays properly in iOS Simulator, Portrait View but no other views work and will display blank white screen instead.
In order to see if your views are actually being drawn and just off screen as others have suggested capture the view hierarchy. Go to 'debug' in the menu, then in 'view debugging' click capture view hierarchy. This will pause your app and create a 3D representation of all view on your screen which you can move around by clicking and dragging.
Are your views actually being drawn? If yes are they drawing off screen? If yes then you need to fix your constraints.
It sounds like you haven't set your constraints appropriately. Try setting the top and leading constraints for each of your views to something less than 320 (should cover all device sizes). Fix your warnings, then try again. I believe the views are simply off the screen.
You don't have the correct auto-layout UIConstraints set in interface builder. Check the document outline view in interface builder and ensure that you have appropriate constraints set on each view.
Auto Layout issues occur when you create conflicting constraints, when you don’t provide enough constraints, or when the final layout contains a set of constraints that are ambiguous.
Check this Apple documentation out, it will show you step by step how to resolve your (common) issue.

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.

iPhone app's storyboard does not display correctly on iPad

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.

portrait layout wont scroll in landscape orientation

Im quite new to XCode and Interface Builder, so forgive me if the solution is obvious.
I have designed a nice portrait IPhone view in interface builder (XCode 5) and have set the constraints on each of the elements (labels, text views, switches, buttons etc) so that they are positioned correctly in either 3.5 or 4 inch portait mode in the simulator.
However, when I rotate the simulator to landscape it breaks the design with elements overlaying each other and other elements disappearing (being clipped from the view) - and I expected this.
My idea of a solution is to put all of the UI elements inside a UIScrollView and set constraints on the scroll view so that it fills the screen in either portait of landscape mode.
After doing this, the portrait view is as before in the simulator, but in landscape view nothing scrolls, and none of my UI elements respect their constraints (stretch horizontally etc). Im still losing UI at the bottom and I cant scroll it into view.
I assumed that putting everything into the scroll view would simply 'fix' this issue, but the scroll view seems to do absolutely nothing at all. I have fiddled with various settings in interface builder but nothing fixes this.
There seem to be lots of long-winded solutions to this type of scenario based on code, but surely something this simple and common should just 'work'
What am I missing, or what have I done wrong, or does simple scrolling really have to be extensively coded in order to work ???
Putting all of your elements inside a scroll view won't really solve anything. Those elements would still need constraints to know how to position themselves in the scroll view. You need to be careful as well, as this solution sounds like something that goes against apples human interface guidelines. I'd advise against ignoring those, as Apple are known to reject apps that do this.
I'd say your problem is your constraints simply aren't setup correctly if elements are cover other elements and moving into the wrong places when rotated.
Annoyingly the WWDC videos section of the developer site is still down, but when it's back up, have a watch of the video of autolayout in Xcode 5, it will help explain what's going on.
If you want elements to completely change position when rotated however, you're likely to need more than just constraints, and would need to throw in some code to handle the transition between portrait and landscape. So it really depends on what the view is supposed to do when you rotate the device
OK, Ive figured it out. It IS a bug in either XCode 5 or IOS 7
I created 2 simple iphone UI's in interface builder - one in Xcode 4.6.3 targeting IOS 6.1 and the other in XCode 5 Beta 4 targeting IOS 7 beta 4.
The first app ran entirely as I had assumed, with the scroll view scrolling in landscape mode. The second app had no scrolling at all in the scroll view - so obviously a bug.

Resources