initial commit
This commit is contained in:
114
Example/SellyCloudSDK/Controllers/AVTabBarController.m
Normal file
114
Example/SellyCloudSDK/Controllers/AVTabBarController.m
Normal file
@@ -0,0 +1,114 @@
|
||||
//
|
||||
// AVTabBarController.m
|
||||
// AVDemo
|
||||
//
|
||||
|
||||
#import "AVTabBarController.h"
|
||||
#import "AVHomeViewController.h"
|
||||
#import "AVCallViewController.h"
|
||||
#import "AVSettingsViewController.h"
|
||||
#import "AVLoginViewController.h"
|
||||
#import "AVUserManager.h"
|
||||
|
||||
@interface AVTabBarController () <AVLoginViewControllerDelegate>
|
||||
@end
|
||||
|
||||
@implementation AVTabBarController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
// Create Home tab
|
||||
AVHomeViewController *homeVC = [[AVHomeViewController alloc] init];
|
||||
UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:homeVC];
|
||||
homeNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页"
|
||||
image:[UIImage systemImageNamed:@"house"]
|
||||
selectedImage:[UIImage systemImageNamed:@"house.fill"]];
|
||||
|
||||
// Create Call tab
|
||||
AVCallViewController *callVC = [[AVCallViewController alloc] init];
|
||||
UINavigationController *callNav = [[UINavigationController alloc] initWithRootViewController:callVC];
|
||||
callNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"通话"
|
||||
image:[UIImage systemImageNamed:@"phone"]
|
||||
selectedImage:[UIImage systemImageNamed:@"phone.fill"]];
|
||||
|
||||
// Create Settings tab
|
||||
AVSettingsViewController *settingsVC = [[AVSettingsViewController alloc] init];
|
||||
UINavigationController *settingsNav = [[UINavigationController alloc] initWithRootViewController:settingsVC];
|
||||
settingsNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"设置"
|
||||
image:[UIImage systemImageNamed:@"gearshape"]
|
||||
selectedImage:[UIImage systemImageNamed:@"gearshape.fill"]];
|
||||
|
||||
// Set view controllers
|
||||
self.viewControllers = @[homeNav, callNav, settingsNav];
|
||||
|
||||
// Customize tab bar appearance
|
||||
self.tabBar.tintColor = [UIColor systemBlueColor];
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
|
||||
// 检查登录状态
|
||||
[self checkLoginStatus];
|
||||
}
|
||||
|
||||
#pragma mark - Login Management
|
||||
|
||||
- (void)checkLoginStatus {
|
||||
// 如果未登录,显示登录页面
|
||||
if (![AVUserManager sharedManager].isLoggedIn) {
|
||||
[self showLoginViewController];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showLoginViewController {
|
||||
AVLoginViewController *loginVC = [[AVLoginViewController alloc] init];
|
||||
loginVC.delegate = self;
|
||||
loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||
|
||||
// 确保不会重复弹出登录页面
|
||||
if (self.presentedViewController == nil) {
|
||||
[self presentViewController:loginVC animated:YES completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - AVLoginViewControllerDelegate
|
||||
|
||||
- (void)loginViewControllerDidLogin:(AVLoginViewController *)controller {
|
||||
// 登录成功,关闭登录页面
|
||||
[controller dismissViewControllerAnimated:YES completion:^{
|
||||
NSLog(@"✅ 登录成功,已进入应用");
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Orientation Support (将方向决策交给顶层 ViewController)
|
||||
|
||||
- (BOOL)shouldAutorotate {
|
||||
// 返回当前显示的 NavigationController 的顶层 VC 的设置
|
||||
UINavigationController *nav = (UINavigationController *)self.selectedViewController;
|
||||
if ([nav isKindOfClass:[UINavigationController class]]) {
|
||||
return [nav.topViewController shouldAutorotate];
|
||||
}
|
||||
return [self.selectedViewController shouldAutorotate];
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
|
||||
// 返回当前显示的 NavigationController 的顶层 VC 的设置
|
||||
UINavigationController *nav = (UINavigationController *)self.selectedViewController;
|
||||
if ([nav isKindOfClass:[UINavigationController class]]) {
|
||||
return [nav.topViewController supportedInterfaceOrientations];
|
||||
}
|
||||
return [self.selectedViewController supportedInterfaceOrientations];
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
|
||||
// 返回当前显示的 NavigationController 的顶层 VC 的设置
|
||||
UINavigationController *nav = (UINavigationController *)self.selectedViewController;
|
||||
if ([nav isKindOfClass:[UINavigationController class]]) {
|
||||
return [nav.topViewController preferredInterfaceOrientationForPresentation];
|
||||
}
|
||||
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user