PDA

View Full Version : Code to rotate a view




RutgerB
Apr 1, 2009, 08:10 AM
Hi


In my application some views support landscape orientation and some don't.
I have a function to go to another view.

When I'm in one view that supports landscape and I press a button to go to a view that does not support landscape mode the view should be rotated to portrait. So even when your still holding the iPhone in landscape the view is in portrait.

What I need is a function that wil rotate the view.


Thanks
Rutger



blackmesa
Apr 1, 2009, 09:11 AM
You should do a transformation. Try looking at: CGAffineTransformMakeRotation


Also try googling:uiview rotate

Sergio10
May 15, 2009, 11:31 AM
I have the same problem:

I have in IB:
- ViewController
- UIView1
- Uiview2

So, I inserted UIView1 in IB to ViewController like a subview and overrided method:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

UIView1 is show in portrait position correctly.

When I want to show another view (UIView2) I develop:

viewController.view = view2;


It shows but not in PORTRAIT view? Why? How to solve this problem?

Sergio10
May 15, 2009, 04:31 PM
I think problem is with the window(UIWindow)

Because when I wrote:

viewController.view = playfieldView;
[window addSubview: viewController.view];
[window makeKeyAndVisible];

All is fine. View in horizontal position.

But if I wrote like this:

viewController.view = mainMenu;
[window addSubview: viewController.view];

viewController.view = playfieldView;
[window addSubview: viewController.view];
[window makeKeyAndVisible];

Then view doesn't rotate ((((
Why? How to solve this problem?