开发者

iPad Rotation, Any Way To Load Custom View Based On Orientation?

开发者 https://www.devze.com 2023-01-05 01:09 出处:网络
Im writing an app that I would like to display different views based on orientation. For example, if the device is portrait load pView, if landscape load lView. Below is the code ive currently tried.

Im writing an app that I would like to display different views based on orientation. For example, if the device is portrait load pView, if landscape load lView. Below is the code ive currently tried.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation durat开发者_如何学编程ion:(NSTimeInterval)duration {
 if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
      self.view = portrait;
}
 else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
      self.view = landscape;
 }

}

With this I have created 2 views in IB and connected the outlets to the right view. Ive also tried this:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
 if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
      self.view = portrait;
}
 else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      self.view = portrait;
 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
      lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
      [self.navigationController pushViewController:abo animated:NO];
      [abo release];

 }
 else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
      lView *abo = [[lView alloc] initWithNibName:@"lView" bundle:nil];
      [self.navigationController pushViewController:abo animated:NO];
      [abo release];

 }

}

The code directly above worked for ipod but not ipad. Any ideas?


I found the following 2 (Apple) sample projects useful:

http://developer.apple.com/library/ios/#samplecode/AlternateViews/Introduction/Intro.html

http://developer.apple.com/library/ios/#samplecode/WhichWayIsUp/Introduction/Intro.html

Also, remember from a device perspective there is also face-up and face-down orientations; this caught me out.


I have to ask the obvious question:

Do you have the screen orientation lock switch turned on for your iPad?


Depending on what you are trying to do, you can set up your interface in IB to handle rotations automatically. You can resize components, move pics and labels around, stuff like that. That may do what you want to do...

0

精彩评论

暂无评论...
验证码 换一张
取 消