Donovan
Donovan

Reputation: 6132

UIView ipad rotation

I see a few questions about this here, but I can't really understand what exactly I should do to implement rotation of UIViews.

I have two Default pngs for Landscape and Portrait mode, but how the view knows that at a particular time it has to rotate his own content? What methods I should implement, and what allows me to change orientation when the device is rotated/change orientation when the app starts with the device not in default orientation?

I should implement also a callback for orientation change notification? And, if yes, how can I do all this?

I just need some clear information. I'm a bit confused.

Thank you in advance, —Albé

Upvotes: 0

Views: 1878

Answers (2)

nevan king
nevan king

Reputation: 113777

Here's a method I use in a universal app (iPad and iPhone). My iPhone version doesn't change orientation, but the iPad version does. The UIInterfaceOrientationPortrait check might be redundant.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return YES; // supports all orientations
    }
    if (interfaceOrientation == UIInterfaceOrientationPortrait) {
        return YES;
    }
    return NO;
}

This method goes into any view that I want to support rotation.

There's also a key in the Info.plist for general and iPad rotation. The iPad version is UISupportedInterfaceOrientations~ipad

Upvotes: 1

slf
slf

Reputation: 22777

I think what you might be looking for is actually on the UIViewController. See Responding to View Rotation Events in the class reference, and of course the View Controller Programming Guide. Your view controller instance will get these messages from the OS as it monitors the device state, and it is the standard prescription for responding to basic device orientation change.

If for whatever reason, you determine that this easy, native functionality for rotation is inadequate for you, you can of course manipulate UIView's however you like. That is detailed in the Core Animation Programming Guide, essentially you manipulate the geometry by changing the Layer transform with functions like CATransform3DMakeRotation.

This SO article has good info on best practices.

Upvotes: 2

Related Questions