风景xib显示为肖像 [英] Landscape xib appears as portrait

查看:115
本文介绍了风景xib显示为肖像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图控制器和纵向和横向的单独nib文件。在旋转时,我加载相应的笔尖。方法

I have a view controller and separate nib files for portrait and landscape. On rotating, I load the respective nib. The methods

 shouldAutorotateToInterfaceOrientation and willRotateToInterfaceOrientation

被调用并且笔尖确实发生了变化。

get called and the nib does change.

问题:

the landscape nib does not appear as landscape, but portrait! The status bar is
correctly rotated and appears on the top:
(Sorry, couldn't paste the image, because my account is new. The screenshot is in   
landscape, with a landscape status bar, but a landscape view shown as portrait.)

有人会认为问题在于没有设置方向为IB中的横向视图的模拟度量,但我已经完成了,视图在IB中显示为横向。 (如果视图是纵向的话,我认为甚至不可能创建一个旋转的按钮。)除了这两个笔尖我还有一个 mainwindow.xib ,其中包含app delegate,window并且查看控制器对象。

One would think the problem lies in not setting the orientation as Landscape in IB Simulated metrics for the view, but I've done that and the view appears as landscape in IB. (I don't think it would even be possible to create a rotated button like that if the view was portrait.) Besides these two nibs I have a mainwindow.xib, which contains the app delegate, window and view controller objects.

编辑:当他们应该熬夜时,我意识到视图实际上正在旋转。就像有一个额外的转变。当我将手机向右旋转90°时,风景xib会向右旋转90°。当我将手机向右旋转90°时,纵向xib会上下颠倒显示。状态栏始终正确显示在顶部。

I realized that the views are actually rotating, when they should "stay up". It's like there's an extra transformation. When I rotate the phone 90° right, the landscape xib is displayed rotated 90° right. When I rotate the phone another 90° right, the portrait xib is displayed upside down. The status bar is always correctly displayed at the top.

EDIT2:使用

self.view.transform = CGAffineTransformMakeRotation((M_PI * (90) / 180.0));

in willRotateToInterfaceOrientation我可以将视图旋转到横向左侧(以及我想要的任何方向),所以我可以使用它作为一种解决方法。但是,我有其他项目,视图自动旋转,不需要使用CGAffineTransformMakeRotation。这就像阻止自动旋转一样。

in willRotateToInterfaceOrientation I can rotate the view to landscape left (and to any orientation I want), so I can use that as a workaround. However, I have other projects, where the view rotates automatically and doesn't require the use of CGAffineTransformMakeRotation. It's like something is preventing the automatic rotation here.

推荐答案

我做过类似的事情,而不是分别制作一个nib文件我刚刚将两个子视图添加到主笔尖作为prtraitView和Landscape View

I had done something similar to this only instead of making an nib file separately I just added two subviews to the main nib as prtraitView and Landscape View

并将其切换如下

In viewDidAppear方法

In viewDidAppear method

-(void)viewDidAppear:(BOOL)animated{




    if(UIDeviceOrientationIsPortrait(self.interfaceOrientation))
    {
        self.portraitVIew.frame=self.view.bounds;
        self.portraitVIew.frame=self.view.frame;
        [self.view addSubview:self.portraitVIew];
    }else{
        self.landscapeView.frame=self.view.frame;
        [self.view addSubview:self.landscapeView];
    }
    self.view.autoresizesSubviews = YES;




    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(deviceOrientationDidChangeNotification:)
     name:UIDeviceOrientationDidChangeNotification
     object:nil];


}

然后按如下方式实施deviceOrientationDidChangeNotification

and then Implemented deviceOrientationDidChangeNotification as follows

- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{

    if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad) {

    }else{
        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if(UIDeviceOrientationIsLandscape(self.interfaceOrientation))
        {
            self.landscapeView.hidden=NO;
            self.landscapeView.frame=self.view.frame;
            [self.portraitVIew removeFromSuperview];


            [self.view addSubview:self.landscapeView];
        }else {
            self.landscapeView.hidden=YES;
            self.portraitVIew.frame=self.view.frame;
            NSLog(@"Portrait");

            [self.view addSubview:self.portraitVIew];
        }
    }



}

对我来说效果很好..

It worked very well for me..

这篇关于风景xib显示为肖像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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