Лучшие практики для поддержки книжной и альбомной ориентации интерфейса в iPad iOS 4.3 - PullRequest
0 голосов
/ 26 января 2012

В документе

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

они использовали executeSegueWithIdentifier: sender: и dismissViewControllerAnimated: завершение: , которые доступны вiOS 5.0 и более поздние версии.

Существует ли какой-либо разумный способ использовать несколько перьев для разных ориентаций интерфейса ipad в iOS 4.3.

1 Ответ

0 голосов
/ 01 июня 2012

Допустим, у вас есть 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/

...