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

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.

Related

Subviews incorrect size?

Let me start off with saying that I am no expert in iOS Development or Objective-C.
I am making a app for a local charity(its a church) and they want it to support rotation.
The app work as expected if started in portrait mode, I can choose my new subview and the rotate it works perfectly.
However I need it to work so they can rotate at any time. The Main view(the one loaded on startup) already does this out of the box; but my subviews do not.
I have attached 3 screenshots below to try and explain what I mean.
This is how it looks in portrait mode:
In landscape:
and back to portrait it I started the app rotated:
If it helps I add the subview like this:
dailyPrayerView = [[DailyPrayerView alloc] initWithNibName:#"DailyPrayerView" bundle:nil];
[self.view addSubview:dailyPrayerView.view];
Does anybody have any ideas why this is?
Check the autoresizing mask in Interface Builder. It's on the sizes pane of the Utilities pane. You should be able to make it stretch to fit the screen, rather than staying at a constant size.

Fitting views for Portrait and Landscape for iPad

I am coming onto a project that only looks good in landscape view. When I switch to portrait, it looks like all the elements stay where they are and things do not get resized to fit the view. Some of the content on certain pages might not fit in portrait mode at all based on how things are already laid out in landscape.
If I want to make the app look good in both orientations, is my best bet to play around with the resizing on the size inspector for views that items will fit fine.
And then for views where items do not fit easily, rethink the design and either use some iPad functionality like popover, or create a separate view to display the data differently instead of just resizing?
Thanks.
Quite a bit can be achieved by playing with resizing controls in IB (especially the ones that stick the control to a side - sometimes it may be not very obvious, like "stiking"the control that's on top to the bottom side).
However, a much more robust solution is to have a method that would reposition/resize all your controls depending on the screen size (1024x768 or 768x1024). Then call it whenever the device is rotated.
Such a method is also quite handy for other purposes - e.g. if you have a view that is only sometimes visible (like an ad), you'll need to resize the rest to a non-full-screen size.

different theme for landscape and portrait mode

Let me explain what I am creating and it will be nice if someone could tell me a better approach.
I am creating an app that supports all orientations. The app is like a power point presentation with several slides with several images and basic functionality in each slide. the functionality is very simple such as showing an image or moving an image when a button is pressed for example. So creating the app is not the problem. Since this app has to support all orientations when the device enters portrait mode I need to move the content in order to make it fit for the portrait orientation. And I would have to do the same thing if it enters landscape mode. Because there is so much content in every slide I need to change the content very much when changing orientation. so an image in portrait mode might have cords (20,5) and on landscape mode that image will have totally different coordinates.
So is there a way that I can set the IBOutlets have specific cords on landscape and specific cords on portrait with xcode. It takes me forever to store the cords of every IBOutlet in an array since I have so many IBOutles in each slide. I have to store the CGPoints in an array with the cords of IBOutlets in landscape and portrait mode and then if the device enters landsape mode set it's center equal to the array elemets. THIS IS SIMPLE BUT IT TAKES FOREVER!
Moreover I am creating many xib files and treat each xib as a different slide in my app.
With what you are saying, you need two xibs for each "slide". One that describes the portrait orientation, and one that describes the landscape orientation.

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

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.

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.