在 iPad iOS 4.3 中支持纵向和横向界面方向的最佳实践
Posted
技术标签:
【中文标题】在 iPad iOS 4.3 中支持纵向和横向界面方向的最佳实践【英文标题】:Best practice to support portrait and landscape interface orientations in a iPad iOS 4.3 【发布时间】:2012-01-26 08:17:39 【问题描述】:在文档中,
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html#//apple_ref/doc/uid/TP40007457-CH7-SW6
他们使用了 iOS 5.0 及更高版本中可用的 performSegueWithIdentifier:sender: 和 dismissViewControllerAnimated:completion:。
在 iOS 4.3 中是否有任何智能方法可以将多个笔尖用于不同的 ipad 界面方向。
【问题讨论】:
【参考方案1】:假设您有一个 PortraitViewController 和一个 LandscapeViewController。
您将需要以下物品:
@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
致谢:http://www.edumobile.org/iphone/iphone-programming-tutorials/alternativeviews-in-iphone/
【讨论】:
以上是关于在 iPad iOS 4.3 中支持纵向和横向界面方向的最佳实践的主要内容,如果未能解决你的问题,请参考以下文章
我可以为 iPhone 和 iPad(纵向和横向)使用单独的故事板吗?