#import "RootViewController.h"
#import "LoginViewController.h"
#import "RegistViewController.h"
#import "PasswardViewController.h"
#import "RootView.h" @interface RootViewController ()
@property (nonatomic, strong) RootView *rootView;
@property (nonatomic, strong) LoginViewController *loginVC;
@property (nonatomic, strong) RegistViewController *registVC;
@property (nonatomic, strong) PasswardViewController *passwardVC; @end @implementation RootViewController - (void)loadView {
self.rootView = [[RootView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.rootView; } - (void)viewDidLoad {
[super viewDidLoad]; // 初始化视图控制器
self.loginVC = [[LoginViewController alloc] init];
self.registVC = [[RegistViewController alloc] init];
self.passwardVC = [[PasswardViewController alloc] init]; // segment添加一个事件
[self.rootView.segment addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged]; } // 实现点击事件
- (void)click:(UISegmentedControl *)sender { switch (sender.selectedSegmentIndex) {
case :
// 移除父视图中最上面的子视图
[[self.rootView.subviews objectAtIndex:] removeFromSuperview]; // 添加新视图
[self.rootView addSubview:self.loginVC.view]; // 把分段选择器显示在最外层
[self.rootView bringSubviewToFront:self.rootView.segment];
break; case :
// 移除父视图中最上面的子视图
[[self.rootView.subviews objectAtIndex:] removeFromSuperview]; // 添加新视图
[self.rootView addSubview:self.registVC.view]; // 把分段选择器显示在最外层
[self.rootView bringSubviewToFront:self.rootView.segment];
break; case :
// 移除父视图中最上面的子视图
[[self.rootView.subviews objectAtIndex:] removeFromSuperview]; // 添加新视图
[self.rootView addSubview:self.passwardVC.view]; // 把分段选择器显示在最外层
[self.rootView bringSubviewToFront:self.rootView.segment];
break; default:
break;
}
}
@end
04-28 08:34