使用目标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;
}];
}
}
更新
更新1:
故事板侧板。
答案 0 :(得分:1)
确保@property (weak, nonatomic) IBOutlet UIView *containerViewA;
和@property (weak, nonatomic) IBOutlet UIView *containerViewB;
正确连接。