想要将muliple笔尖用于不同的iphone界面方向 [英] Want to use muliple nibs for different iphone interface orientations

查看:101
本文介绍了想要将muliple笔尖用于不同的iphone界面方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我创建了两个不同的笔尖,一个在纵向模式,另一个在横向模式。我在视图中有很多设计,所以我不得不选择两个不同的笔尖。现在,我想切换nibs,因为界面在

I have a situation, I have created two different nibs, one in Portrait Mode and other in Landscape mode. I had lots of designs in the view so, i had to opt for two different nibs. Now, I want to toggle the nibs as the interface rotates in the


公共viewController

这样我就可以保留填充值和视图中控件的状态。

so that I can retain the filled values and the state of the controls I have in the view.

现在我正在使用

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight ){
    [self initWithNibName:@"LandscapeNib" bundle:nil];
}else if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
    [self initWithNibName:@"PortraitNib" bundle:nil];

}


return YES;

}

但它没有更改Nib,它显示初始加载的笔尖。我猜它是加载但没有显示,因为初始笔尖已经显示,不会被删除。我无法找到使用通用视图控制器处理多个笔尖的解决方案,以便我可以轻松处理控件的功能?

but it doesn't changes the Nib, it shows the initial loaded nib. May I guess it is loading but not showing because initial nib is already showing, is not removed. I am not able to find the solution of working with multiple nibs with a common view controller so that I can easily handle the functionality of the controls ?

推荐答案

您应该为横向模式创建一个特殊的视图控制器,并在设备旋转时以模态方式显示它。要在设备旋转时收到通知,请注册 UIDeviceOrientationDidChangeNotification 通知。

You should create a special view-controller for landscape mode, and present it modally when device rotates. To be notified when device rotates, register for UIDeviceOrientationDidChangeNotification notifications.

对于需要以不同方式呈现的此类复杂视图在纵向和横向中,这是Apple实施它的推荐方式。阅读此处了解更多详情:

For such complex views that need to be presented differently in portrait and landscape, this is recommended way of implementing it by Apple. Read here for more details:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html#//apple_ref/ doc / uid / TP40007457-CH101-SW26

这是Apple文档的一个片段。在init或awakeFromNib中注册通知:

Here's a snippet from Apple's documentation. Register for notifications in your init or awakeFromNib:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
   [[NSNotificationCenter defaultCenter] addObserver:self
                             selector:@selector(orientationChanged:)
                             name:UIDeviceOrientationDidChangeNotification
                             object:nil];

并且在orientationChanged中根据当前轮换以模态方式或解除它来呈现您的横向视图控制器:

and in orientationChanged present your landscape view-controller modally, or dismiss it, all according to current rotation:

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        !isShowingLandscapeView)
    {
        [self presentModalViewController:self.landscapeViewController
                                animated:YES];
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait &&
             isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }
}

这篇关于想要将muliple笔尖用于不同的iphone界面方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆