2012-01-26 18 views
0

、彼らはperformSegueWithIdentifier使用している肖像画や風景インターフェイスの向きをサポートするためのベストプラクティス4.3

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html#//apple_ref/doc/uid/TP40007457-CH7-SW6

:送信者:dismissViewControllerAnimated:完了:でご利用いただけますiOS 5.0以降。

iOS 4.3で異なるipadインターフェイスの向きに複数のnibを使用するスマートな方法はありますか?

答えて

0

あなたが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/

次が必要になります

関連する問題