使用分段控制器处理两个容器视图

时间:2017-08-11 05:35:34

标签: ios uisegmentedcontrol uicontainerview

使用目标c学习容器视图。

在这里,尝试使用分段控制器逐个显示两个容器。 两个容器使用容器名称是containerViewA,containerViewB。 我正在运行应用程序,那时只有containerViewB被加载。

代码:

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *containerViewA;
@property (weak, nonatomic) IBOutlet UIView *containerViewB;
@end

- (IBAction)ShowComponent:(UISegmentedControl *)sender {
    if (sender.selectedSegmentIndex == 0) {
        [UIView animateWithDuration:(0.5) animations:^{
            self.containerViewA.alpha = 1;
            self.containerViewB.alpha = 0;
        }];
    } else {
        [UIView animateWithDuration:(0.5) animations:^{
            self.containerViewA.alpha = 0;
            self.containerViewB.alpha = 1;
        }];
    }
} 

更新

enter image description here

更新1:

故事板侧板。

enter image description here

1 个答案:

答案 0 :(得分:1)

确保@property (weak, nonatomic) IBOutlet UIView *containerViewA;@property (weak, nonatomic) IBOutlet UIView *containerViewB;正确连接。