|
//
// loginFrontPageController.m
// ThePaperDemo
//
// Created by scar1900 on 14/12/4.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "loginFrontPageController.h"
#import "shareUtil.h"
#import "userSystemViewModel.h"
#import "mobilePhoneAndEmailConfirmController.h"
#import "forgetPwdConfirmController.h"
@interface loginFrontPageController () <userSystemViewModel> {
CGFloat lastKeyboradHeight;
}
@property(nonatomic, strong)UIButton *wechatBtn;
@property(nonatomic, strong)UILabel *wechatLabel;
@property(nonatomic, strong)UIButton *qqBtn;
@property(nonatomic, strong)UILabel *qqLabel;
@property(nonatomic, strong)UIButton *sinaBtn;
@property(nonatomic, strong)UILabel *sinaLabel;
@property(nonatomic, strong)UIButton *doubanBtn;
@property(nonatomic, strong)UILabel *doubanLabel;
@property(nonatomic, strong)UIImageView *userImageView;
@property(nonatomic, strong)UITextField *userNameField;
@property(nonatomic, strong)UIView *userLine;
@property(nonatomic, strong)UIImageView *passwordImageView;
@property(nonatomic, strong)UITextField *passwordField;
@property(nonatomic, strong)UIView *passwordLine;
@property(nonatomic, strong)TPCustomButton *loginBtn;
@property(nonatomic, strong)TPCustomButton *registerBtn;
@property(nonatomic, strong)TPCustomButton *forgetPwdBtn;
@property(nonatomic, strong)userSystemViewModel *viewModel;
@end
@implementation loginFrontPageController
- (void)viewDidLoad {
[super viewDidLoad];
_viewModel = [userSystemViewModel new];
_viewModel.delegate = self;
self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.keyboardView.contentSize = CGSizeMake(rect_screen.size.width, 450);
self.keyboardView.scrollEnabled = YES;
lastKeyboradHeight = 0;
if ([shareUtil isHaveWeChatClient]) {
[self.keyboardView addSubview:self.wechatBtn];
[self.keyboardView addSubview:self.wechatLabel];
}
[self.keyboardView addSubview:self.qqBtn];
[self.keyboardView addSubview:self.qqLabel];
[self.keyboardView addSubview:self.sinaBtn];
[self.keyboardView addSubview:self.sinaLabel];
[self.keyboardView addSubview:self.doubanBtn];
[self.keyboardView addSubview:self.doubanLabel];
[self.keyboardView addSubview:self.userImageView];
[self.keyboardView addSubview:self.userNameField];
[self.keyboardView addSubview:self.userLine];
[self.keyboardView addSubview:self.passwordImageView];
[self.keyboardView addSubview:self.passwordField];
[self.keyboardView addSubview:self.passwordLine];
[self.keyboardView addSubview:self.loginBtn];
[self.keyboardView addSubview:self.registerBtn];
[self.keyboardView addSubview:self.forgetPwdBtn];
if ([shareUtil isHaveWeChatClient]) {
[self layoutViews];
}
else {
[self layoutViewsWithNoWechat];
}
}
- (void)viewDidLayoutSubviews {
self.keyboardView.contentSize = CGSizeMake(rect_screen.size.width, 450);
[super viewDidLayoutSubviews];
}
- (void)layoutViews {
CGFloat btnWidth = (rect_screen.size.width-40-5*3)/4;
[self.wechatBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.keyboardView.top).offset(30);
make.left.equalTo(self.keyboardView.left).offset(20);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.wechatLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.wechatBtn.bottom).offset(10);
make.left.equalTo(self.wechatBtn.left);
make.right.equalTo(self.wechatBtn.right);
make.height.mas_equalTo(@12);
}];
[self.qqBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.wechatBtn.right).offset(5);
make.top.equalTo(self.wechatBtn.top);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.qqLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.qqBtn.bottom).offset(10);
make.left.equalTo(self.qqBtn.left);
make.right.equalTo(self.qqBtn.right);
make.height.mas_equalTo(@12);
}];
[self.sinaBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.qqBtn.right).offset(5);
make.top.equalTo(self.wechatBtn.top);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.sinaLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.sinaBtn.bottom).offset(10);
make.left.equalTo(self.sinaBtn.left);
make.right.equalTo(self.sinaBtn.right);
make.height.mas_equalTo(@12);
}];
[self.doubanBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.sinaBtn.right).offset(5);
make.top.equalTo(self.wechatBtn.top);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.doubanLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.doubanBtn.bottom).offset(10);
make.left.equalTo(self.doubanBtn.left);
make.right.equalTo(self.doubanBtn.right);
make.height.mas_equalTo(@12);
}];
[self.userImageView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.left).offset(20);
make.bottom.equalTo(self.userNameField.bottom);
make.width.mas_equalTo(@17.5);
make.height.mas_equalTo(@18);
}];
[self.userNameField makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.wechatLabel.bottom).offset(67);
make.left.equalTo(self.view.left).offset(46);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@19);
}];
[self.userLine makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.userNameField.bottom).offset(8);
make.left.equalTo(self.view.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@1);
}];
[self.passwordImageView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.left).offset(20);
make.bottom.equalTo(self.passwordField.bottom);
make.width.mas_equalTo(@18);
make.height.mas_equalTo(@20);
}];
[self.passwordField makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.userNameField.bottom).offset(45);
make.left.equalTo(self.userNameField.left);
make.right.equalTo(self.userNameField.right);
make.height.mas_equalTo(@19);
}];
[self.passwordLine makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.passwordField.bottom).offset(8);
make.left.equalTo(self.view.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@1);
}];
[self.loginBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.passwordLine.bottom).offset(30);
make.left.equalTo(self.view.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@40);
}];
[self.registerBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.loginBtn.bottom).offset(30);
make.left.equalTo(self.view.left).offset(20);
make.height.mas_equalTo(@40);
}];
[self.forgetPwdBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.registerBtn.top);
make.left.equalTo(self.registerBtn.right).offset(10);
make.right.equalTo(self.view.right).offset(-20);
make.width.equalTo(self.registerBtn.width);
make.height.mas_equalTo(@40);
}];
}
- (void)layoutViewsWithNoWechat {
CGFloat btnWidth = (rect_screen.size.width-40-40*2)/3;
[self.qqBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.keyboardView.top).offset(30);
make.left.equalTo(self.keyboardView.left).offset(20);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.qqLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.qqBtn.bottom).offset(10);
make.left.equalTo(self.qqBtn.left);
make.right.equalTo(self.qqBtn.right);
make.height.mas_equalTo(@12);
}];
[self.sinaBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.qqBtn.right).offset(40);
make.top.equalTo(self.qqBtn.top);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.sinaLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.sinaBtn.bottom).offset(10);
make.left.equalTo(self.sinaBtn.left);
make.right.equalTo(self.sinaBtn.right);
make.height.mas_equalTo(@12);
}];
[self.doubanBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.sinaBtn.right).offset(40);
make.top.equalTo(self.qqBtn.top);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.doubanLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.doubanBtn.bottom).offset(10);
make.left.equalTo(self.doubanBtn.left);
make.right.equalTo(self.doubanBtn.right);
make.height.mas_equalTo(@12);
}];
[self.userImageView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.left).offset(20);
make.bottom.equalTo(self.userNameField.bottom);
make.width.mas_equalTo(@17.5);
make.height.mas_equalTo(@18);
}];
[self.userNameField makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.qqLabel.bottom).offset(67);
make.left.equalTo(self.view.left).offset(46);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@19);
}];
[self.userLine makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.userNameField.bottom).offset(8);
make.left.equalTo(self.view.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@1);
}];
[self.passwordImageView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.left).offset(20);
make.bottom.equalTo(self.passwordField.bottom);
make.width.mas_equalTo(@18);
make.height.mas_equalTo(@20);
}];
[self.passwordField makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.userNameField.bottom).offset(45);
make.left.equalTo(self.userNameField.left);
make.right.equalTo(self.userNameField.right);
make.height.mas_equalTo(@19);
}];
[self.passwordLine makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.passwordField.bottom).offset(8);
make.left.equalTo(self.view.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@1);
}];
[self.loginBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.passwordLine.bottom).offset(30);
make.left.equalTo(self.view.left).offset(20);
make.right.equalTo(self.view.right).offset(-20);
make.height.mas_equalTo(@40);
}];
[self.registerBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.loginBtn.bottom).offset(30);
make.left.equalTo(self.view.left).offset(20);
make.height.mas_equalTo(@40);
}];
[self.forgetPwdBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.registerBtn.top);
make.left.equalTo(self.registerBtn.right).offset(10);
make.right.equalTo(self.view.right).offset(-20);
make.width.equalTo(self.registerBtn.width);
make.height.mas_equalTo(@40);
}];
}
#pragma mark - property set and get
- (UIButton*)wechatBtn {
if (!_wechatBtn) {
_wechatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_wechatBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b24d"])
forState:UIControlStateNormal];
[_wechatBtn addTarget:self action:@selector(wechatSocietyLogin:) forControlEvents:UIControlEventTouchUpInside];
if (![shareUtil isHaveWeChatClient]) {
_wechatBtn.enabled = NO;
}else {
_wechatBtn.enabled = YES;
}
[self setButtonHiligthAndDisableColor:_wechatBtn];
_wechatBtn.layer.cornerRadius = 4.f;
_wechatBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"login/shareWeChat.png");
CGSize size = btnImageView.image.size;
[_wechatBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_wechatBtn.center);
// make.height.equalTo(_wechatBtn.height).multipliedBy(0.35);
// make.width.equalTo(btnImageView.height).multipliedBy(size.width/size.height);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _wechatBtn;
}
- (UILabel*)wechatLabel {
if (!_wechatLabel) {
_wechatLabel = [[UILabel alloc] init];
_wechatLabel.textColor = [UIColor colorWithHexString:TextBlack];
_wechatLabel.textAlignment = NSTextAlignmentCenter;
_wechatLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_wechatLabel.text = @"微信登录";
}
return _wechatLabel;
}
- (UIButton*)qqBtn {
if (!_qqBtn) {
_qqBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_qqBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x5da3e9"])
forState:UIControlStateNormal];
[_qqBtn addTarget:self action:@selector(QQSocietyLogin:) forControlEvents:UIControlEventTouchUpInside];
[self setButtonHiligthAndDisableColor:_qqBtn];
_qqBtn.layer.cornerRadius = 4.f;
_qqBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"login/shareQQFriend.png");
CGSize size = btnImageView.image.size;
[_qqBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_qqBtn.center);
// make.height.equalTo(_qqBtn.height).multipliedBy(0.35);
// make.width.equalTo(btnImageView.height).multipliedBy(size.width/size.height);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _qqBtn;
}
- (UILabel*)qqLabel {
if (!_qqLabel) {
_qqLabel = [[UILabel alloc] init];
_qqLabel.textColor = [UIColor colorWithHexString:TextBlack];
_qqLabel.textAlignment = NSTextAlignmentCenter;
_qqLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_qqLabel.text = @"QQ登录";
}
return _qqLabel;
}
- (UIButton*)sinaBtn {
if (!_sinaBtn) {
_sinaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_sinaBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xca7e3d"])
forState:UIControlStateNormal];
[_sinaBtn addTarget:self action:@selector(sinaSocietyLogin:) forControlEvents:UIControlEventTouchUpInside];
[self setButtonHiligthAndDisableColor:_sinaBtn];
_sinaBtn.layer.cornerRadius = 4.f;
_sinaBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"login/shareSinaWeiBo.png");
CGSize size = btnImageView.image.size;
[_sinaBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_sinaBtn.center);
// make.height.equalTo(_sinaBtn.height).multipliedBy(0.35);
// make.width.equalTo(btnImageView.height).multipliedBy(size.width/size.height);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _sinaBtn;
}
- (UILabel*)sinaLabel {
if (!_sinaLabel) {
_sinaLabel = [[UILabel alloc] init];
_sinaLabel.textColor = [UIColor colorWithHexString:TextBlack];
_sinaLabel.textAlignment = NSTextAlignmentCenter;
_sinaLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_sinaLabel.text = @"微博登录";
}
return _sinaLabel;
}
- (UIButton*)doubanBtn {
if (!_doubanBtn) {
_doubanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_doubanBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b24d"])
forState:UIControlStateNormal];
[_doubanBtn addTarget:self action:@selector(doubanSocietyLogin:) forControlEvents:UIControlEventTouchUpInside];
[self setButtonHiligthAndDisableColor:_doubanBtn];
_doubanBtn.layer.cornerRadius = 4.f;
_doubanBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"login/shareDouban.png");
CGSize size = btnImageView.image.size;
[_doubanBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_doubanBtn.center);
// make.height.equalTo(_doubanBtn.height).multipliedBy(0.35);
// make.width.equalTo(btnImageView.height).multipliedBy(size.width/size.height);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _doubanBtn;
}
- (UILabel*)doubanLabel {
if (!_doubanLabel) {
_doubanLabel = [[UILabel alloc] init];
_doubanLabel.textColor = [UIColor colorWithHexString:TextBlack];
_doubanLabel.textAlignment = NSTextAlignmentCenter;
_doubanLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_doubanLabel.text = @"豆瓣登录";
}
return _doubanLabel;
}
- (UIImageView*)userImageView {
if (!_userImageView) {
_userImageView = [[UIImageView alloc] init];
_userImageView.image = Image(@"login/head.png");
}
return _userImageView;
}
- (UITextField*)userNameField {
if (!_userNameField) {
_userNameField = [[UITextField alloc] init];
_userNameField.delegate = self;
_userNameField.backgroundColor = [UIColor clearColor];
NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"手机或电子邮箱" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}];
_userNameField.attributedPlaceholder = atrString;
_userNameField.textColor = [UIColor colorWithHexString:TextBlack];
_userNameField.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
_userNameField.textAlignment = NSTextAlignmentLeft;
_userNameField.keyboardAppearance = UIKeyboardAppearanceDefault;
if ([[TPUserDefault instance].isNightMode intValue] > 0) {
_userNameField.keyboardAppearance = UIKeyboardAppearanceDark;
}
_userNameField.keyboardType = UIKeyboardTypeEmailAddress;
_userNameField.clearButtonMode = UITextFieldViewModeWhileEditing;
[_userNameField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
return _userNameField;
}
- (UIView*)userLine {
if (!_userLine) {
_userLine = [[UIView alloc] init];
_userLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _userLine;
}
- (UIImageView*)passwordImageView {
if (!_passwordImageView) {
_passwordImageView = [[UIImageView alloc] init];
_passwordImageView.image = Image(@"login/password.png");
}
return _passwordImageView;
}
- (UITextField*)passwordField {
if (!_passwordField) {
_passwordField = [[UITextField alloc] init];
_passwordField.delegate = self;
_passwordField.backgroundColor = [UIColor clearColor];
NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"密码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:TextLightGray]}];
_passwordField.attributedPlaceholder = atrString;
_passwordField.textColor = [UIColor colorWithHexString:TextBlack];
_passwordField.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
_passwordField.textAlignment = NSTextAlignmentLeft;
_passwordField.keyboardAppearance = UIKeyboardAppearanceDefault;
if ([[TPUserDefault instance].isNightMode intValue] > 0) {
_passwordField.keyboardAppearance = UIKeyboardAppearanceDark;
}
_passwordField.keyboardType = UIKeyboardTypeASCIICapable;
_passwordField.secureTextEntry = YES;
_passwordField.clearButtonMode = UITextFieldViewModeWhileEditing;
[_passwordField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
_passwordField.returnKeyType = UIReturnKeyDone; //bug:5035 关于密码的地方,键盘都改成“确定”
}
return _passwordField;
}
- (UIView*)passwordLine {
if (!_passwordLine) {
_passwordLine = [[UIView alloc] init];
_passwordLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _passwordLine;
}
- (TPCustomButton*)loginBtn {
if (!_loginBtn) {
_loginBtn = [[TPCustomButton alloc] init];
_loginBtn.title = @"登 录";
[_loginBtn addTarget:self action:@selector(customLogin) forControlEvents:UIControlEventTouchUpInside];
}
return _loginBtn;
}
- (TPCustomButton*)registerBtn {
if (!_registerBtn) {
_registerBtn = [[TPCustomButton alloc] init];
_registerBtn.title = @"注 册";
[_registerBtn addTarget:self action:@selector(registerEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _registerBtn;
}
- (TPCustomButton*)forgetPwdBtn {
if (!_forgetPwdBtn) {
_forgetPwdBtn = [[TPCustomButton alloc] init];
_forgetPwdBtn.title = @"忘记密码";
[_forgetPwdBtn addTarget:self action:@selector(forgetPwd:) forControlEvents:UIControlEventTouchUpInside];
}
return _forgetPwdBtn;
}
- (void)setButtonHiligthAndDisableColor:(UIButton*)btn {
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK])
forState:UIControlStateHighlighted];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONDISABLEBACK])
forState:UIControlStateDisabled];
}
#pragma mark - button event handler
- (void)textFieldDidChange:(UITextField *)textField {
// TPLOG(@"textField Text:%@",textField.text);
if ([textField.text isMatchedByRegex:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]"]) {
textField.text = disable_emoji(textField.text);
}
if (textField == self.userNameField) {
_viewModel.userName = textField.text;
}else if (textField == self.passwordField) {
_viewModel.password = textField.text;
}
}
- (void)wechatSocietyLogin:(UIButton*)btn {
[self closeKeyBoard];
[self.viewModel wechatSocietyLogin];
}
- (void)QQSocietyLogin:(UIButton*)btn {
[self closeKeyBoard];
[self.viewModel QQSocietyLogin];
}
- (void)sinaSocietyLogin:(UIButton*)btn {
[self closeKeyBoard];
[self.viewModel sinaSocietyLogin];
}
- (void)doubanSocietyLogin:(UIButton*)btn {
[self closeKeyBoard];
[self.viewModel doubanSocietyLogin];
}
- (void)customLogin {
[self closeKeyBoard];
[self.viewModel customLogin];
}
- (void)registerEvent:(UIButton*)btn {
mobilePhoneAndEmailConfirmController *confirmVC = [mobilePhoneAndEmailConfirmController new];
[self.navigationController pushViewController:confirmVC animated:YES];
}
- (void)forgetPwd:(UIButton*)btn {
forgetPwdConfirmController *confirmVC = [forgetPwdConfirmController new];
[self.navigationController pushViewController:confirmVC animated:YES];
}
- (void)startHud {
[self.view addSubview:self.waitBackView];
[self.view bringSubviewToFront:self.waitBackView];
self.waitCursor.animating = YES;
}
- (void)stopHud {
[self.waitBackView removeFromSuperview];
self.waitBackView = nil;
self.waitCursor.animating = NO;
}
#pragma mark - textfield delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == _userNameField) {
[_passwordField becomeFirstResponder];
}
else if (textField == _passwordField) {
[self customLogin];
}
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([textField isFirstResponder]) {
if ([[[textField textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textField textInputMode] primaryLanguage]) {
return NO;
}
}
return YES;
}
#pragma mark - viewmodel delegate
- (void)customLoginSuccess {
[[NSNotificationCenter defaultCenter] postNotificationName:HAVELOGIN object:nil];
}
#pragma mark - keyboard handler
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification {
//获取键盘的高度
NSDictionary *userInfo = [aNotification userInfo];
CGRect keyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardRect.size.height;
if (lastKeyboradHeight != keyboardHeight) {
lastKeyboradHeight = keyboardHeight;
if ([_userNameField isFirstResponder]) {
CGFloat responderHeight = CGRectGetMaxY(_passwordLine.frame);
if (responderHeight>(CGRectGetHeight(self.keyboardView.frame)-keyboardHeight)) {
keyboardOffset = responderHeight- (CGRectGetHeight(self.keyboardView.frame)-keyboardHeight);
[self.keyboardView setContentOffset:CGPointMake(0, keyboardOffset)];
self.keyboardView.scrollEnabled = YES;
}
}
else if ([_passwordField isFirstResponder]) {
CGFloat responderHeight = CGRectGetMaxY(_loginBtn.frame);
if (responderHeight>(CGRectGetHeight(self.keyboardView.frame)-keyboardHeight)) {
keyboardOffset = responderHeight- (CGRectGetHeight(self.keyboardView.frame)-keyboardHeight);
[self.keyboardView setContentOffset:CGPointMake(0, keyboardOffset)];
self.keyboardView.scrollEnabled = YES;
}
}
}
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
CGPoint currentOffset = self.keyboardView.contentOffset;
currentOffset.y = currentOffset.y - keyboardOffset;
[self.keyboardView setContentOffset:currentOffset];
keyboardOffset = 0;
lastKeyboradHeight = 0;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
|