在iPad iOS 4.3中支持纵向和横向界面方向的最佳实践
在文件中, 他们使用了在iOS 5.0及更高版本中可用的performsguewithidentifier:sender:和dismissViewControllerAnimated:completion:在iPad iOS 4.3中支持纵向和横向界面方向的最佳实践,ipad,ios4,uiviewcontroller,orientation,nib,Ipad,Ios4,Uiviewcontroller,Orientation,Nib,在文件中, 他们使用了在iOS 5.0及更高版本中可用的performsguewithidentifier:sender:和dismissViewControllerAnimated:completion: 在iOS 4.3中,是否有任何聪明的方法可以为不同的ipad界面方向使用多个NIB。假设您有一个肖像视图控制器和一个景观视图控制器 您将需要以下内容: @interface PortraitViewController : UIViewController { BOOL isSho
在iOS 4.3中,是否有任何聪明的方法可以为不同的ipad界面方向使用多个NIB。假设您有一个肖像视图控制器和一个景观视图控制器 您将需要以下内容:
@interface PortraitViewController : UIViewController {
BOOL isShowingLandscapeView;
LandscapeViewController *landscapeViewController;
}
@implementation PortraitViewController
- (void)viewDidLoad
{
[super viewDidLoad];
landscapeMainViewController = [[LandscapeMainViewController alloc] initWithNibName:@"LandscapeMainViewController" bundle:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[landscapeMainViewController release]; landscapeMainViewController = nil;
[super dealloc];
}
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:landscapeMainViewController animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
@interface LandscapeViewController : UIViewController
@end
@implementation LandscapeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.wantsFullScreenLayout = YES;
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@end
学分: