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



我正在开发一个ViewController,它基于UISegmentControl切换视图。在查看了这个关于堆栈溢出的问题后,我在网上找到了一个教程

主视图控制器是一个选项卡视图控制器,然后在其中一个选项卡上有一个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];    
}

等等。

通过以不同的方式实现它来解决这个问题,如下所示http://redartisan.com/2010/6/27/uisegmented-control-view-switching-revisited

最新更新