UIView loaded from segment managing view is not resizing in landscape mode - iphone

SegmentManagingView
I am trying to do something like above link. I set the Rotation code in my segmentmanagingview
But it is not resizing in landscape mode.Table's width is 320 px in landscape and portrait mode.Any other way to achieve this?

First read Apple's Why won't my UIViewController rotate with the device or the many links on SO to see if rotation is being allowed. Most of the time this will fix it. Other approaches are:
Implement didRotateFromInterfaceOrientation and implement a relocation (setting new centers for each view).
Duplicate the view and swap the subviews (iterating the subviews and replacing one with the other).
Switch views (create a landscape and portrait view on the same nib and change the active view).
There are examples for all three techniques on the iPhone Developer's Cookbook from Erica Sadun. The source code is free to download, look for chapters 2-3.

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

Camera Overlay height for both iphone 4 and iphone 5

I'm using the standard UIImagePickerController and using a camera overlay view with it, default controls. I've got an external nib file which I load the overlay view from. The problem is that the view seems to be at 460, so doesn't fully encompass the camera view on iphone 5. I'd like to approach this using auto layout, but I'm not sure how to tell the nib to adjust it's size to be either a height for iphone 4 or iphone 5.
I thought about using setFrame, but that's very un-auto layout. I've also thought about having 2 different nib files, one for iphone 4 and one for iphone 5, but that seems to be the wrong approach too. I'm guessing there's some way to tell the nib to fill the current camera view, but I'm not sure what it is. Can someone recommend the "correct" way to handle this?
You can programmatically load a different cameraOverlayView XIB based on the phone dimensions. The camera controls strip is about 54px tall on 480h screens, and about 96px tall on 568h screens.
Alternatively, you can certainly design your XIB with auto resizing masks set appropriately, but will need to then do a setFrame in code to get the right dimensions.
So either way, you're writing some code to detect the screen bounds and either loading a different XIB or doing a setFrame.
I haven't used nibs for a while now (preferred storyboard) but I believe what you have so far is a UIImageView in the nib, right? Make that an outlet. And then in your m file, check for dimension of the device (many people have asked this recently how to check screen dimension), then you set the uiimageview frame based on the found dimensions. It should work ;)

Hide DetaiViewController in UISplitViewController in portrait orientation

i want know if it's possibile to hide the DetailViewController in portrait orientation for the UISplitController template ipad example, and let use the MasterViewController in full screen in portrait orientation, and when the orientation change to landascape use the normal UISplitViewController view, with masterview on the left and detail view on the right...it's possible?
Apple's UISplitViewController has been given a very specific behavior, and cannot be customized this way...
In my company, we had to implement our own SplitViewController - our intent was to handle different display of 'masterViewController' when in portrait orientation, different sizes for both controllers in landscape orientation (than those allowed by UISplitViewController), and a different way to handle 'masterViewController' display in portrait orientation -
This heavy customization led us to deal with all kinds of problems regarding UIViewController containing others UIViewControllers - (UIViewControllers containement wasn't supported by Apple before iOS 5 ! see CoconutKit on Github, or this example for workaround examples...).
For your specific needs, here's Matt Gemmell's own attempt at implementing custom SplitViewController , it's quite good, you can still fork the code to make it fit your own needs.

How to do orientation rotation like built-in Calc app?

I'm trying to make an app that handles orientation/rotation similarly to the way the built-in Calc app does.
If you check out that app, in portrait mode there's a normal calculator, and if you rotate to landscape mode there are additional buttons that appear to the left.
I can't figure out how to do this by setting the autosize masks. The problem is the "normal" calculator view is 320px wide in portrait mode, but actually shrinks to around 240px in landscape mode to fit the additional controls.
I've seen examples like the AlternateViews sample app that have two different view controllers (one for portrait and one for landscape), but they don't seem to animate the transitions between the views nicely like the Calc app does.
I've also tried setting the frames for the views manually in willAnimateSecondHalfOfRotationFromInterfaceOrientation, but it doesn't seem to look "quite right" and also I'm not certain how that works with the autoresize mask.
Any ideas how this is done? Thanks!
Just override the following method call:
- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Inside of there resize all of your components so they look nice.

What's the best way to handle landscape/portrait differences in IB?

I have a view that supports landscape and portrait viewing, with the controls all moving around when you switch from one to the other. I'm currently doing this by setting the .center of each one of my controls when the user rotates the phone. The problem is that this is tedious, and requires a lot of code, and seems to defeat the purpose of using Interface Builder in the first place.
My question is: is there a way in Interface Builder for one view to support multiple looks (one for landscape one for portrait)? If not how do other people do this with IB? Do you set up 2 views?
Edit: Just to clarify my landscape and portrait views look different, I don't want a straight transform, I actually display the data differently in landscape mode
When necessary, I add UIView objects to the view in IB which I make hidden. Give it a nice background color so you can see it, and send it all the way to the background. Then use that view's frame when you need to set the frame of an object. If you have a lot of them, you might consider using UILabel instead, so you can give it a visible name in IB.
If you're worried about memory issues, just remove all these extra UIViews in ViewDidLoad and just store their frame values in member CGRects. This only works of course if you don't have any of the views auto-resize or reposition on rotate, which you probably shouldn't anyway, in this case. I do this for resizing/repositioning for any reason, not just when the screen rotates.
I'm not 100% sure if it's possible, but have you considered using different view controllers for landscape and portrait?
The AutoSize attributes of IBOutlet objects in the Size Inspector of IB (command 3) give some pretty nice options for auto-stretching and positioning of items. You can control L/R and T/B screen positions and relative width and height. You can't get full control of the layout, but most of the basic operations are there.
The only way one view can support multiple orientations in IB is to set the autosizing mask of components to either scale and/or anchor to edges. To design a totally different layout for each orientation you need to design a portrait and landscape view separately (each in its own XIB) and switch between them programatically.