123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- //
- // RootViewController.m
- // XenonSDK
- //
- // Created by SAGESSE on 2019/5/29.
- // Copyright © 2019 SAGESSE. All rights reserved.
- //
- #import "XenonSDK.h"
- #import "XSUtils.h"
- #import "RootViewController.h"
- #import "NavigationAnimator.h"
- #import "HelperViewController.h"
- #import "UserLoginPhoneViewController.h"
- #import "UserLoginAccountViewController.h"
- #import "UserRegisterAccountViewController.h"
- #import "UserProtocolViewController.h"
- #import "UserRestPasswordViewController.h"
- #import "UserRestPassword2ViewController.h"
- #import "UserPrivacyProlicyViewController.h"
- #import "UserForgetPasswordViewController.h"
- @interface RootViewController () <UINavigationControllerDelegate>
- @property (nonatomic, strong) id keybardInfo;
- @end
- @implementation RootViewController
- - (instancetype)initWithRootViewController:(UIViewController*)rootViewController {
- self = [self initWithNibName:nil bundle:XenonSDK.sharedSDK.bundle];
-
- self.embedViewController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
-
- self.modalPresentationStyle = UIModalPresentationOverFullScreen;
- self.embedViewController.delegate = self;
- return self;
- }
- - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- return [super initWithNibName:@"RootViewController" bundle:nibBundleOrNil];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- //
- self.view.backgroundColor = UIColor.clearColor;
- [self.view addSubview:self.embedView];
- [self viewWillLayoutSubviews];
-
- // Update font size dynamically.
- if (self.titleLabel != nil) {
- self.titleLabel.font = [self.titleLabel.font fontWithSize:CGFloatBasedI414(26)];
-
- // foce load view.
- (void)self.embedViewController.topViewController.view;
- // self.titleLabel.text = (self.embedViewController.topViewController as? BaseViewController)?.topTitle
- }
- if (self.theme == nil) {
- UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:self.view.bounds];
- toolbar.barStyle = UIBarStyleDefault;
- toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- toolbar.userInteractionEnabled = false;
- //toolbar.setShadowImage(UIImage(), forToolbarPosition: .any)
- [self.embedView insertSubview:toolbar atIndex:0];
- }
- //self.embedController.isNavigationBarHidden = true
- self.embedViewController.view.frame = self.embedView.bounds;
- self.embedViewController.view.backgroundColor = UIColor.clearColor;
- self.embedViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- // self.embedViewController.navigationBar.isTranslucent = true
- // self.embedViewController.navigationBar.setBackgroundImage(.init(), for: .default)
- // self.embedViewController.navigationBar.shadowImage = .init()
- self.embedViewController.navigationBarHidden = true;
- [self addChildViewController:self.embedViewController];
- [self.embedView addSubview:self.embedViewController.view];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(textFieldWillEditing:) name:UITextFieldTextDidBeginEditingNotification object:nil];
-
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
- [NSNotificationCenter.defaultCenter removeObserver:self];
- }
- - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
- return [[NavigationAnimator alloc] initWithOperation:operation titleView:_titleLabel];
- }
- // MARK: -
- - (void)textFieldWillEditing:(id)sender {
- if (self.keybardInfo != nil) {
- [self keyboardWillShow:self.keybardInfo];
- }
- }
- // Get current firset responder in ui hierarchy.
- - (id)firstResponderInResponder:(id)responder {
- if ([responder isFirstResponder]) {
- return responder;
- }
- if ([responder isKindOfClass:UIViewController.class]) {
- return [self firstResponderInResponder:[responder view]];
- }
- if ([responder isKindOfClass:UIView.class]) {
- for (UIView* view in [responder subviews]) {
- id r = [self firstResponderInResponder:view];
- if (r != nil) {
- return r;
- }
- }
- }
-
- return nil;
- }
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [super touchesEnded:touches withEvent:event];
-
- // Resign all first responder.
- [self.view endEditing:YES];
- }
- /// When show keyboard add view animation.
- - (void)keyboardWillShow:(NSNotification*)sender {
-
- // Gets the UITextField in first responder.
- NSDictionary* userInfo = sender.userInfo;
- UITextField* firstResponder = (id)[self firstResponderInResponder:self.view];
- if (userInfo == nil || firstResponder == nil) {
- return;
- }
- CGRect textField = [firstResponder convertRect:firstResponder.bounds toView:self.view];
-
- // Get animation duration.
- NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
- CGRect frame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGFloat offset = fmin((CGRectGetMinY(frame) - textField.size.height) / 2 - CGRectGetMinY(textField), 0);
-
- // Make animation.
- [UIView animateWithDuration:duration animations:^{
- UIViewAnimationCurve type = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];;
- [UIView setAnimationCurve:type];
-
- self.view.transform = CGAffineTransformMakeTranslation(0, offset);
- }];
-
- // Save keyboard info.
- self.keybardInfo = sender;
- }
- /// When hide keyboard add view animation.
- - (void)keyboardWillHide:(NSNotification*)sender {
-
-
- // Get animation duration.
- NSDictionary* userInfo = sender.userInfo;
- NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
- [UIView animateWithDuration:duration animations:^{
- UIViewAnimationCurve type = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];;
- [UIView setAnimationCurve:type];
-
- self.view.transform = CGAffineTransformIdentity;
- }];
-
- // Clean keybard info.
- self.keybardInfo = nil;
- }
- @end
- @implementation UIViewController (XenonSDK)
- - (void)sdk_dismissViewController:(id)sender {
-
- if (self.navigationController.viewControllers.count <= 1) {
- [self dismissViewControllerAnimated:YES completion:nil];
- return;
- }
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)sdk_showViewControllerForPhoneLogin:(id)sender {
- [self.view endEditing:YES];
- [self.navigationController pushViewController:UserLoginPhoneViewController.new animated:YES];
- }
- // MARK: -
- #pragma mark - =======forgetPassword Action======
- - (void)sdk_showViewControllerForForgetPasswod:(id)sender {
- [self.view endEditing:YES];
- [self.navigationController pushViewController:UserForgetPasswordViewController.new animated:YES];
-
- }
- - (void)sdk_showViewControllerForResetPasswod:(id)sender {
- [self.view endEditing:YES];
- [self.navigationController pushViewController:UserRestPassword2ViewController.new animated:YES];
- }
- ///用户隐私协议
- - (void)sdk_showViewControllerForUserPrivacy:(id)sender {
-
- [self.view endEditing:YES];
- UserPrivacyProlicyViewController *prolicyVc = [[UserPrivacyProlicyViewController alloc]init];
- [self presentViewController:prolicyVc animated:YES completion:nil];
- }
- //用户注册协议
- - (void)sdk_showViewControllerForUserProtocol:(id)sender {
-
- [self.view endEditing:YES];
- [self.navigationController pushViewController:UserProtocolViewController.new animated:YES];
-
-
-
-
- }
- - (void)sdk_showViewControllerForCustomerService:(id)sender {
- [self.view endEditing:YES];
- [self.navigationController pushViewController:HelperViewController.new animated:YES];
- }
- @end
- @implementation UITextField (XenonSDK)
- - (void)setPlaceholderColor:(UIColor*)color {
-
- if (color == nil) {
- self.placeholder = self.placeholder;
- return;
- }
- if (self.placeholder == nil) {
- return;
- }
- id mas = [[NSMutableAttributedString alloc] initWithString:self.placeholder attributes:@{NSForegroundColorAttributeName: color}];
- self.attributedPlaceholder = mas;
- }
- - (UIColor*)placeholderColor {
- return nil;
- }
- @end
- @implementation CALayer (XenonSDK)
- - (void)setCornerRadiusBasedI375:(CGFloat)radius {
- self.cornerRadius = CGFloatBasedI375(radius);
- }
- - (CGFloat)cornerRadiusBasedI375 {
- return self.cornerRadius;
- }
- @end
|