【发布时间】:2012-01-26 08:17:39
【问题描述】:
在文档中,
他们使用了 iOS 5.0 及更高版本中可用的 performSegueWithIdentifier:sender: 和 dismissViewControllerAnimated:completion:。
在 iOS 4.3 中是否有任何智能方法可以将多个笔尖用于不同的 ipad 界面方向。
【问题讨论】:
标签: ipad ios4 uiviewcontroller orientation nib
在文档中,
他们使用了 iOS 5.0 及更高版本中可用的 performSegueWithIdentifier:sender: 和 dismissViewControllerAnimated:completion:。
在 iOS 4.3 中是否有任何智能方法可以将多个笔尖用于不同的 ipad 界面方向。
【问题讨论】:
标签: ipad ios4 uiviewcontroller orientation nib
假设您有一个 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/
【讨论】: