使用控制器控制其他控制器时视图大小的问题

时间:2012-07-26 08:39:53

标签: iphone ios uiviewcontroller rotation uisegmentedcontrol

我正在研究一个基于UISegmentControl切换视图的ViewController。在查看此tutorial

后,我在网上找到了question on stack overflow

主视图控制器是一个标签视图控制器,然后在其中一个标签上有一个uinavigationcontroller,它包含一个分段控件(希望你还在我身边)。 我遇到的问题是分段控件中视图的高度。第一个选定的视图正确调整大小,但段控件中的所有其他视图忽略了那里有一个标签栏,并且标签栏下有视图。

我尝试添加以下内容,但似乎没有帮助。

controller1.view.autoresizesSubviews = YES;
controller1.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

controller2.view.autoresizesSubviews = YES;
controller2.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

有什么想法吗?

另一个问题是轮换。如果我在分段视图上旋转。当前选定的视图将旋转,如果我更改分段,视图将不会旋转到横向,并且只会占据屏幕的一小部分(如下所示)。

我已经覆盖了SegmentedViewController中所有与旋转相关的方法,并循环了它正在管理和调用的方法数组。不幸的是,这似乎没有完成这项工作。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];     

    for (UIViewController * viewController in self.segmentedViewControllers) 
        [viewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];    

    for (UIViewController * viewController in self.segmentedViewControllers) 
        [viewController didRotateFromInterfaceOrientation:fromInterfaceOrientation];

}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];    

    for (UIViewController * viewController in self.segmentedViewControllers) 
        [viewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];    
}

等...

1 个答案:

答案 0 :(得分:1)

通过以http://redartisan.com/2010/6/27/uisegmented-control-view-switching-revisited

所示的不同方式实施,以解决此问题