M使用目標c學習Container視圖。使用分段控制器使用兩個容器視圖
在此,嘗試使用分段控制器逐個顯示兩個容器。 兩個容器使用容器名稱是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:
故事板側板。
是什麼問題? – Akhilrajtr
第一個容器不顯示。@ Akhilrajtr –
請嘗試在if之前打印sender.selectedSegmentIndex的值,並告訴它是什麼? – 3stud1ant3