1

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

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

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

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

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

有任何想法吗?

另一个问题是旋转。如果我在分段视图上旋转。当前选择的视图会旋转,如果我改变segment,视图不会旋转到横向,只会占屏幕的一小部分(如下图)。

我已经覆盖了 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];    
}

等等……</p>

4

1 回答 1

1

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

于 2012-10-13T22:14:33.143 回答