Is it possible to auto-rotate a modal view but not its parent? - iphone

It seems that if a modal view's parent returns false to shouldAutoRotate... the modal view will also not autorotate. How can I have a main view which will never rotate, and a modal view which will always rotate?

You may try to observe for orientation events (UIDeviceOrientationDidChangeNotification) in your modal view controller and then add a transformation to your view layer using the CATransform3DMakeRotation to get an appropriate rotation around Z or basically with
[myLayer setValue:[NSNumber numberWithInt:M_PI*0.5f] forKeyPath:#"transform.rotation.z"]; // or - M_PI*0.5f depending orientation: left or right
You can also use an animation to get an animated rotation. Is it what you're asking for?
For observing orientation events read this chapter :
Getting the Current Device Orientation
For Layer transform read this chapter :
Layer Geometry and Transforms
Regards.
V.Zgueb

Yeah, sure you can. Pretty much same advice like here I've posted recently just in different direction.
You need allow rotation on Modal, witch is by default. And disable it on Main controller.
This should work fine.

Related

[iPhone]how to add transition animation or overlay view when screen is rotating

My application has some screens support landscape mode which load some more data and have to re-render GUI, and one of them will load another view in landscape mode. But its seem the screen would be rotated before re-rendered or load another view, it is not nice looking.
So it would be better if there is an animation or a view to be shown when rotating.
Does anyone know how to do this please help me! Thanks so much!
You can do either one (or both); display additional animations or display a different view while rotating. I'm assuming you're working with a UIViewController, check out the documentation (specifically, 'Handling View Rotations').
Override both willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation: to add and then remove your placeholder view.
You will need to override willAnimateRotationToInterfaceOrientation:duration: to perform any animations.

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 can I smoothly transition between separate Portrait and Landscape UIViewControllers?

I'm using Apple's sample code for having separate Portrait and Landscape view controllers (presenting/dismissing a modal view controller from within the orientationChanged method). However, it creates a number of problems:
The status bar doesn't rotate. If I manually setStatusBarOrientation, I get very strange behavior.
The transition is very abrupt; I prefer
the conventional smooth animation,
especially because...
90% of the
view changes, but there are two
images which should look exactly the
same (same size, same position, same
orientation) in both the landscape
and portrait modes.
My goal is a rotation transition more like the one in the Stocks app. How can I achieve this?
Thanks.
You could use core animation to do that. Fade out all elements that don't appear in the other view (by animating the opacity). Move and rotate the objects that are the same in each view. And finally fade in new objects in the second view. It might get rather complicated, depending on the complexity of your view. Have a look at these methods to find out where to implement the animations:
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
– didAnimateFirstHalfOfRotationToInterfaceOrientation:
– willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:

preventing a specific view from auto rotating... is that possible?

I have a view based app. Its self.view has several subviews and shouldAutorotateToInterfaceOrientation is returning YES.
When I rotate the device, all views rotate as expected.
Is that possible to prevent a subview from auto rotating even if the view's parent is auto rotating?
Keep in mind that it's the view controller that controls what happens during rotation and not the view itself. You can't stop a subview from rotating by setting a property, or something relatively easy, if its parent view's UIViewController is set to auto rotate. You can, however, have sibling views where one rotates and the other doesn't. It's probably possible to layout your views the way you want but not have the one that shouldn't rotate as a subview of a rotating UIViewController.
You could probably write some code that will reorient a subview so it appears not to rotate when the parent view does rotate, however.

iPhone force rotation

I have been reading a ton on rotation, but not finding a solution to my query. Here goes:
I have a portrait application with a tabbar and hidden navigation controller in my tab. At a point in the app, the next view must be landscape.
The XIB layout has been done in landscape, so I want to bring up the xib without any translation or pixel moving code. (not thinking this is required) I have tried just pushing the view (remains in portrait), shifting the view using various methods (non seem to line thing up properly).
Is there a way to tell the view that it is already laid out for landscape prior to it being opened?
Thanks in advance!
Found it, this code does the trick in the viewdidload:
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
Still have 1 odd thing. No matter what I do to set the navigation bar to hidden, it does not rotate, and stays at the left side of the view.
[[self navigationController] setNavigationBarHidden:YES animated:NO];
Has anyone seed this behavior and solved?
I'm positive that you cannot 'force' a rotation. The system decides when to change the orientation of the device; so the 'orientation' properties are essentially read-only. I looked into this same problem a long time ago when I wanted to make sure a particular view always displayed in one orientation.
Due to this, most apps allow all of their views and view controllers to work in any of the orientations the app supports. I've found that trying to restrict the behavior of some views and view controllers ultimately creates more hassle, and can cause issues when transitioning between views and view controllers.
The code you posted will work for your view. You are not actually changing the orientation at all; your view is just behaving like it has been rotated by drawing in a rotated fashion. I'm not sure if you can do the same thing to the navigation bar or not, but it's worth a shot. If you are able to control the view properties of the navigation bar (it is a UIView as well), applying the same pattern you are using for your custom view should work.
Most apps that want a view to only be in landscape ultimately force their entire app to be in landscape. For instance, Flight Control only supports one orientation. Thus, the drawing code is pretty simple; regardless of orientation, just draw the view and rotate it to the one orientation it supports (either landscape left or right).
Your app's design wouldn't be that easy... it sounds like you are not designing a full-screen app. You would have to worry about the navigation bar and status bar being properly drawn.