【问题标题】:Best practice to support portrait and landscape interface orientations in a iPad iOS 4.3在 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 界面方向。

【问题讨论】:

    标签: ipad ios4 uiviewcontroller orientation nib


    【解决方案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/

    【讨论】:

      猜你喜欢
      • 2015-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 2011-09-10
      • 2015-06-14
      • 2018-10-11
      • 1970-01-01
      相关资源
      最近更新 更多