【问题标题】:Switching to landscape view and using a tab bar controller切换到横向视图并使用标签栏控制器
【发布时间】:2011-11-11 22:07:04
【问题描述】:

我正在为我的应用程序使用标签栏控制器。如果我在一个名为“结果”的视图控制器中并且 ios 设备旋转到横向模式,它会切换到我创建的另一个视图,称为landScape。这已经在方法中完成了

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view=landScape;
    } else {
        self.view=originalView;
    }
}

只要我在选项卡栏中的特定控制器(示例结果视图控制器)中,它就可以正常工作。然而;如果我转到标签栏控制器中的另一个元素并且我的手机在横向模式下倾斜,然后我决定转到 resultsviewcontroller,它不会调用我的视图 landScape,而是尝试自行自动调整视图大小并且看起来可怕。我应该在 viewDidLoad 方法中调用方法 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 来解决问题吗?或者这是完全错误的?

提前谢谢你!

【问题讨论】:

    标签: objective-c ios xcode views


    【解决方案1】:

    问题是您仅在 resultsViewController.view 是活动视图控制器并检测到旋转时才设置它。试试这个:

    - (void)setViewForInterfaceOrientation:(UIInterfaceOrientation)orientation
    {
        self.view = UIInterfaceOrientationIsPortrait(orientation)
            ? originalView
            : landScape;
    }
    
    - (void)viewWillAppear
    {
        [self setViewForInterfaceOrientation:[[UIDevice currentDevice] orientation];
        [super viewWillAppear];
    }
    
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
    {
        [self setViewForInterfaceOrientation:toInterfaceOrientation];
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    }
    

    【讨论】:

    • 感谢罗布的回复。我就是这样做的,你怎么看?
    • -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { self.view=landScape; } 其他 { self.view=originalView; }
    • 把它放在你的...对不起,我是新手
    • @marcus13 你可以添加你自己的答案,甚至是你自己的问题(如果有意义的话)
    • 我已根据您当前的实施更改了答案。
    猜你喜欢
    • 2015-09-08
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    相关资源
    最近更新 更多