Custom size app screen on iPad - iphone

I am trying to create a mid-size screen for my app on iPad.
In didFinishLaunchingWithOptions(), I do this:
CGRect winRect = CGRectMake(100,100,500,500);
navController.view.frame = winRect;
the screen comes up fine and I can click around and do stuff until the orientation changes. It takes the screen to original full size - how can I make it stick to my winRect frame? I tried setting the parentViewController.view.frame/view.frame to winRect in willRotateToInterfaceOrientation() but no good.
Any ideas?
Thanks.

Generally, you shouldn't mess with the frame of a view controller's view. View controllers tend to resize their views on many occasions, for example when toolbars and navigation bars are hidden or made visible or when the interface orientation changes.
For custom-sized views, create a separate view, set its frame to your custom size and add it as a subview to your view controller's view.

Related

Xcode storyboard view on rotation

I would like to have a view to the top or left of the device.
I have tried using a stack view to rotate the view but I was unable to use all interface orientations.
Example: the iPad orientation has a regular width and height in both portrait and landscape orientation. Thus I believe I cannot rotate the stack view axis on this device.
What are other options to keep the view how I want it preferably using the storyboard with auto-layout only but if needed using swift code.
Edit:
To clarify, both the blue and grey view can be seen as empty UIView for the purpose of this question.
To clarify, when you rotate the device, you want the text, buttons, etc to rotate but the background to stay the same (as in the view takes up the same screen area, but things in the view are rotated), correct?
If so, use size classes to give your views different constraints for different views

Iphone View Rotation not functioning properly

I have a simple 1 screen app, with 1 View.. the view contains
a button, an textbox and a button across the top
A segmented controller across the bottom
and a MapView in between.
In portrait mode all is right with the world.. So I decided to begin to allow Orientation change...
in IB all views and elements and even the root window have autoResizeSubviews set
in My AppDelegate and my viewController I have also programatically added SetAutoResizeSubviews to yes explicitely I have set the autoResizingMask in the Root Window and the View Controller to FlexibleWidht | Flexibile Height
I have added the shouldAutorotateToInterfaceOrientation in my ViewController to always return true.
Yet, it doesn't work.. Or should I say it doesn't rotate properly.. in both portrait modes everything looks great, but both landscape modes, things don't get laid out or resized properly.. Basically all I see is the mapview, and its size gets slightly wider, but not much than the portrait mode, and it doesn't fill up the screen top to bottom.. all other interface elements with the exception of one button are invisible and it appears on TOP of the mapview.. as thought it just happened to be layed out over the view by coincidence than any design.
Anyone have any ideas what I am missing, or why?
Thanks in advance
You say "I have set the autoResizingMask in the Root Window and the View Controller" but that is a red herring. It is the buttons, the text box, the segmented controller, and the map view that have to have the correct autoresizingMask. If this view is being designed in the nib, you can set the values there and then turn the orientation right there in the nib and see what happens.
If you are unable to work out good autoresizingMask values for all those interface elements, implement didRotateFromInterfaceOrientation and perform the layout alterations in code when called upon to do so.

Transparency for top UIView not working

In a UINavigationController I have a UITableView. I use a settings-button to allow users changing some table settings.
When the settings-button is tapped I push a new view onto the navigation stack.
This new view has the following view structure
-> UIView1 411 x 320 px (backgroundColor supposed to be transparent) !!!!
-->> UIView2 270 x 300 px (backgroundColor grey)
--->>> Screen elements
My problem is that I want UIView1 to be transparent so that the information behind is still visible. All my attempts, such as
setting the bg color to transparent
changing the alpha value
removing the Opaque indicator
have failed so far.
Any clues? most appreciated!
UINavigationController is not designed to allow "buried" view controllers to still be showing under the current visible view controller. (The iOS framework can actually unload the views of view controllers on the nav stack that aren't the current top item!)
So if you try to do it, it just won't work, or you'll have problems. (Same goes for modal view controllers on the iPhone -- even if you make the background transparent, the view you're pushing on top of will disappear.)
If you really want the old UI to still be visible underneath, consider presenting your new entire UI as a UIView placed over the current view (i.e. do [existingView addSubview:myNewView]).

tabBarController + changing orientation problem

I have a TabBarController with 4 views, and one of them is a scrollView. If i load this view, and then change the orientation of my device from portrait to landscape, the scrollview responds to the touches only 'till the pixel 320.
If later i go to another view, and then come back to the first, the scroll view works well even in landscape.
How can i adjust this?
Your scroll view is probably not set to automatically adjust its height and width. If your view is built with Interface Builder, use the Autosizing section of the Size Inspector to set the struts & springs. Otherwise, if you're building your view programmatically, you'll need to set the autoresizingMask property to something appropriate.

Why are Views loaded from nibs being placed 20 pixels down from the status bar?

I am trying to set up a layout as such in an iPad application. It will have three major views, which make up the whole screen. The views will be stacked one on top of the other, each taking up the full width. I have one major nib file which accounts for the entire screen space. In that nib file, I am instantiating the three view controllers with outlets. Then I have this code:
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:controllerOne.view];
[self.view addSubview:controllerTwo.view];
[self.view addSubview:controllerThree.view];
}
This adds the views on top of one another and 20 pixels lower. However, after rotating to landscape and back they are right under the status bar. Do you know what would be causing this?
I figured out the cause of this. When you are editing the View Controller in Interface Builder, I needed to uncheck "Resize View from Nib." Then it comes in at the frame I set and stays in the right place.