查看方向更改 [英] View Orientation changes

查看:110
本文介绍了查看方向更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我发现为什么它一直在加载相同的视图。我现在解决了这个问题这是一个错字

Update: I found why it was loading the same view the whole time. I now fixed that. It was a typo

ControllerForSplitViews.m

ControllerForSplitViews.m

- (id)init
{
    self = [super initWithNibName:@"ControllerForSplitViews" bundle:nil];
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
        self.view = landscapeView;
    }
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
        self.view = portraintView;
    }
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self     selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    return self;
}

这样做。

现在问题。加载并运行视图时,我更改方向并从同一个nib文件加载不同的视图,修复:但是一旦我这样做,其他UI元素就会消失,只保留我的横向视图的ui元素,当我再次旋转设备它不会再次加载我的纵向视图?有任何建议可能会发生这种情况吗?

Now the problem. When the view is loaded and running I change the orientation and load a different view from the same nib file, Fixed: but as soon as I do this the other UI elements disappears and only the ui elements of my landscape view is kept and when I rotate the device again it doesn't load my portrait view again? Any suggestions why this might happen?

-(void) orientationChanged:(id)object
{   
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
    {
        self.view = portraintView;
    }
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
    {
        self.view = landscapeView;
    }
 }

新问题,每次更改加载的方向相反方向的视图

New Problem, each time I change the orientation it loads the opposite orientation's view

谢谢

推荐答案

好的我找到了修复它有效,但我不知道为什么我的原始代码不能正常工作:

Ok so I found a fix that works, but I have no idea why my original code didn't work what I did was:

删除:

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

删除:

-(void) orientationChanged:(id)object
{   
    if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
    {
        self.view = portraintView;
    }
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
    {
        self.view = landscapeView;
    }
 }

更改:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight))){

        self.view = landscapeView;

    }else if(((interfaceOrientation == UIInterfaceOrientationPortrait) || 
          (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){

        self.view = portraintView;

    }
    return YES;
}

现在它完美运作

这篇关于查看方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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