Changing view size when orientation changes - iphone

I want my UIView subclass to behave so that when it is fitted in portrait orientation is has a certain size and another size when fitted in landscape mode.
Is it possible to have the view indicate to the view controller that's resizing it when the orientation changes that it has this "ideal size"?
To clarify, I'm confident that this is not something that can be done with the autoresizing mask. I also thought that sizeThatFits: would be what I need but I didn't see it get called when the orientation changed.
I'm also aware that I can get this done by overriding layoutSubviews of the superview (or maybe some other method of the view controller but I would like to have this behavior embedded in the view to facilitate reuse.

You get several messages when the device rotates:
- shouldAutorotateToInterfaceOrientation:;
- willRotateToInterfaceOrientation:duration:;
- didRotateFromInterfaceOrientation:
You can use these to re-layout your view when the user rotates.
If you don't want to use a view controller, you can register for the UIDeviceOrientationDidChangeNotification notification.

Related

IOS6 Update view when interface orientation change

I need to reposition a UIPopoverController when interface orientation change. In io5 I just did everything in:willRotateToInterfaceOrientation
I know I can listen to UIDeviceOrientationDidChangeNotification in IOS6, but I only want interface orientation calls.
The ideas behind ios6 rotation are that some views, like popovers, dont really have an orientation. as they dont fill the screen.
To re-layout the view as the size of the popover changes layout your view in -(void)viewWillLayoutSubviews in your popover's content view controller and ajust the views as needed to the new size. Animatable changes are animated.

iPhone Orientation Change

I know how to do an orientation change, but lets say you have a view with buttons, labels, ect. The autoresizing distorts and makes the view look strange. What's the accepted way to do this, do I just create a portrait and landscape view. If so where would I actually do the swapping of these views.
Do all kind of resizing and reposition in your layoutSubviews method of UIView.
Once the orientation is changed, your layoutSubviews would be called then you can know the current orientation by using UIDevice class. and reposition your views child accordingly
UIDevice property to be used for getting current orientation .
#propertyic,readonly) UIDeviceOrientation orientation
My sandbox app:
https://github.com/comonitos/programatical_device_orientation
The solution is easy

Iphone sdk custom uiview orientation issue

I am using custom based uiview controller with uitabbar contains uitableview. I am using image for cell background. I want to do orientation from portrait to landscape but the issue is it is not changing on orientation. I just want to know is there are any special thing for custom uiviewcontroller for orientation?
Thanks in advance
Regards,
sathish
If nothing happens when you rotate the device, you either have the system-wide rotation lock enabled (you checked that, right?), or your view controller isn't returning YES to the alternate orientation in its shouldAutorotateToInterfaceOrientation:, or you're doing something odd with your views that means your view controller isn't getting set as the “frontmost” one and thus isn't getting asked about orientation changes. It'll be easier to narrow that down if you post the code you're using to set up the controller and its view.

iPhone/iOS SDK: Autorotate main view, but not child view?

Here's what I'm trying to do.
I have a single view ("primaryView"), controlled by a customized view controller. primaryView contains a scrollview, which contains an image. Sitting on top of the scroll view (NOT inside it) is a small view ("buttonsView") containing a few buttons.
Basically, when the user rotates the phone, I want buttonsView to autorotate to match the new orientation, but I want the scrollview to remain exactly as it is, and NOT rotate.
Is there a way to do this? Right now, primaryView is autorotating, and taking both subviews (the scrollview and buttonsView) with it, which is no good.
Thanks!
The system will not autorotate unless all visible views consent to autorotation. What you can do, then, is to detect orientation changes, and set an appropriate affine transform for the non-rotating views, essentially to undo the system's rotation.
You can use willRotateToInterfaceOrientation:duration: to fade out the controls, then didRotateFromInterfaceOrientation: to fade them back in at the correct location.

How to determine the frame of a view after an iPhone is rotated, before the rotation actually takes place

I'm currently dealing with an iphone view controller which contains a paging UIScrollView, to display multiple pages of information. My application needs to support a landscape mode, and I've been having a bit of trouble figuring out the right way to implement this.
In order to maintain view continuity, I want to resize my views manually in two steps. First, I override willRotateToInterfaceOrientation. In this method I extend the width of all my views in the paging scroll view to the width that they'll end up at in landscape mode. Then, in didRotateToInterfaceOrientation, I reduce the height of the views to fit the height of the landscape mode.
My question is, how do I determine the new width and height to resize my views? Hardcoding the exact values feels like a bad hack, and I get the sense that there must be an elegant way of solving the problem.
I'm not sure why you're doing layout in didRotateToInterfaceOrientation:, which happens at the end of the rotation. In any case, the new frame should already be set by UIViewController.
If you're going to sync things to the animation, look at willAnimateRotationToInterfaceOrientation:duration:. According to the docs,
This method is called from within the animation block that is used to rotate the view. You can override this method and use it to configure additional animations that should occur during the view rotation. For example, you could use it to adjust the zoom level of your content, change the scroller position, or modify other animatable properties of your view.
By the time this method is called, the interfaceOrientation property is already set to the new orientation. Thus, you can perform any additional layout required by your views in this method.