iPhone Orientation Change - iphone

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

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.

Flip the iPhone screen with a button

how do I implement a button that will flip the screen 180deg for my game (if the user wishes to play it with the iPhone upside-down), and have it affect all of my 5 different views?
You should apply a transform to the parent view (your UIWindow). The rotation can be made using CGAffineTransformMakeRotation().
It might be better to actually allow the device orientation to cause the rotation though. In App settings set that the app supports autorotation and then in the UIViewController return tru to -(BOOL)shouldAutorotateToInterfaceOrientation when the rotation passed in is UIInterfaceOrientationPortraitUpsideDown
Look at shouldAutorotateToInterfaceOrientation. And maybe [myView setNeedsDisplay]; could help.
It sounds like you just want to use the build in automatic orientation rotation. You may need to tell your app in the build settings that it supports the upsidedown orientation and as dasdom mentioned you need to implement shouldAutorotateToInterfaceOrientation in all of your view controllers.
There is no way to force the phone into an orientation on-demand.
If you are looking to just rotate a view you can apply a CGAffineTransform.

Orientation portrait and landscape mode

I have a 2 big logo images. In landscape mode all OK. When I change to portrait mode, the images lay one on the other. They too big for IB alignment
Can I set different views for each orientation?
or how can I fix this problem.
Update to saadnib's answer. Do not use shouldAutorotateToInterfaceOrientation. This method is for something else.
Your methods are:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
The former is called just before rotation occurs and the second one is called just after interface orientation.
You should replace UIViewController's view here or you can replace images for different orientations here too.
Use the following code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
for current orientation and according it change your image view frames.

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.

Changing view size when orientation changes

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.