|
//
// forgetPwdConfirmController.m
// ThePaperHD
//
// Created by scar1900 on 15/3/24.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "forgetPwdConfirmController.h"
#import "MLNavigationController.h"
#import "KGModal.h"
#import "TPCustomButton.h"
#import "confimPwdController.h"
#define TEXTFIELDTAG 2000
@interface forgetPwdConfirmController ()
@property(nonatomic, strong)UIButton *closeBtn;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UITextField *phoneTextField;
@property(nonatomic, strong)UITextField *inviteCodeField;
@property(nonatomic, strong)UIButton *getInviteCodeBtn;
@property(nonatomic, strong)TPCustomButton *confirmBtn;
@end
@implementation forgetPwdConfirmController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if (![TPUserDefault instance].fogetPwdInfoBO) {
[TPUserDefault instance].fogetPwdInfoBO = registerInfoBO.new;
}
self.view.backgroundColor = [UIColor clearColor];
self.view.frame = CGRectMake(0, 0, loginPopUpSize.width, loginPopUpSize.height);
[self.view addSubview:self.closeBtn];
[self.view addSubview:self.titleLabel];
self.closeBtn.frame = CGRectMake(0, 0, 50, 80);
[self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
self.titleLabel.frame = CGRectMake(0,
0,
CGRectGetWidth(self.view.bounds),
80);
self.keyboardView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.keyboardView.frame = CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), loginPopUpSize.width, loginPopUpSize.height-80);
[self.keyboardView addSubview:self.phoneTextField];
[self addTextFieldImage];
[self addLine];
[self.keyboardView addSubview:self.getInviteCodeBtn];
[self.keyboardView addSubview:self.inviteCodeField];
[self.keyboardView addSubview:self.confirmBtn];
self.phoneTextField.text = [TPUserDefault instance].fogetPwdInfoBO.mail?[TPUserDefault instance].fogetPwdInfoBO.mail:@"";
self.inviteCodeField.text = [TPUserDefault instance].fogetPwdInfoBO.verCode?[TPUserDefault instance].fogetPwdInfoBO.verCode:@"";
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
[KGModal sharedInstance].tapOutsideToDismiss = NO;
__weak typeof(self) Self = self;
[[KGModal sharedInstance] setTapHandler:^{
[Self closeKeyBoard];
}];
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
}
- (UIButton*)closeBtn {
if (!_closeBtn) {
_closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeBtn setImage:Image(@"login/popUpBack.png") forState:UIControlStateNormal];
[_closeBtn setImage:Image(@"login/popUpBack_h.png") forState:UIControlStateHighlighted];
[_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.text = @"忘记密码";
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = appFont(30, NO);
}
return _titleLabel;
}
- (UITextField*)phoneTextField {
if (!_phoneTextField) {
_phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(50,
115/2,
loginPopUpSize.width-50-15,
35)];
_phoneTextField.delegate = self;
_phoneTextField.backgroundColor = [UIColor clearColor];
NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"请输入注册时的手机或电子邮箱" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:LINECOLOR]}];
_phoneTextField.attributedPlaceholder = atrString;
_phoneTextField.textColor = [UIColor colorWithHexString:TextBlack];
_phoneTextField.textAlignment = NSTextAlignmentLeft;
_phoneTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
if ([[TPUserDefault instance].isNightMode intValue] > 0) {
_phoneTextField.keyboardAppearance = UIKeyboardAppearanceDark;
}
_phoneTextField.keyboardType = UIKeyboardTypeDefault;
_phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
_phoneTextField.tag = TEXTFIELDTAG+0;
[_phoneTextField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
_phoneTextField.font = appFont(18, NO);
}
return _phoneTextField;
}
- (UIButton*)getInviteCodeBtn {
if (!_getInviteCodeBtn) {
_getInviteCodeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_getInviteCodeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
[_getInviteCodeBtn setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal];
[_getInviteCodeBtn setTitleColor:[UIColor colorWithHexString:BUTTONSELECTBACK] forState:UIControlStateHighlighted];
_getInviteCodeBtn.frame = CGRectMake(loginPopUpSize.width/2-255/4, CGRectGetMaxY(self.phoneTextField.frame)+128/2, 255/2, 64/2);
[_getInviteCodeBtn addTarget:self action:@selector(getInviteCode:) forControlEvents:UIControlEventTouchUpInside];
_getInviteCodeBtn.titleLabel.font = appFont(18, NO);
_getInviteCodeBtn.layer.borderColor = [UIColor colorWithHexString:BLUECOLOR].CGColor;
_getInviteCodeBtn.layer.cornerRadius = 4.f;
_getInviteCodeBtn.layer.borderWidth = 1;
}
return _getInviteCodeBtn;
}
- (UITextField*)inviteCodeField {
if (!_inviteCodeField) {
_inviteCodeField = [[UITextField alloc]initWithFrame:CGRectMake(50,
CGRectGetMaxY(self.getInviteCodeBtn.frame)+128/2,
loginPopUpSize.width-50-15,
35)];
_inviteCodeField.delegate = self;
_inviteCodeField.backgroundColor = [UIColor clearColor];
NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"请输入您收到的验证码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:LINECOLOR]}];
_inviteCodeField.attributedPlaceholder = atrString;
_inviteCodeField.textColor = [UIColor colorWithHexString:TextBlack];
_inviteCodeField.textAlignment = NSTextAlignmentLeft;
_inviteCodeField.keyboardAppearance = UIKeyboardAppearanceDefault;
if ([[TPUserDefault instance].isNightMode intValue] > 0) {
_inviteCodeField.keyboardAppearance = UIKeyboardAppearanceDark;
}
_inviteCodeField.keyboardType = UIKeyboardTypeNumberPad;
_inviteCodeField.clearButtonMode = UITextFieldViewModeWhileEditing;
_inviteCodeField.tag = TEXTFIELDTAG+1;
[_inviteCodeField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
_inviteCodeField.font = appFont(18, NO);
}
return _inviteCodeField;
}
- (TPCustomButton*)confirmBtn {
if (!_confirmBtn) {
_confirmBtn = [[TPCustomButton alloc]initWithFrame:CGRectMake(190/2,
CGRectGetMaxY(self.inviteCodeField.frame)+126/2,
loginPopUpSize.width-190,
40)];
_confirmBtn.title = @"确 认";
[_confirmBtn addTarget:self action:@selector(confirmEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _confirmBtn;
}
- (void)addTextFieldImage {
UIImageView *phoneImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15,
CGRectGetMinY(self.phoneTextField.frame)+3.5,
25,
23)];
phoneImageView.image = Image(@"login/userName.png");
[self.keyboardView addSubview:phoneImageView];
//
UIImageView *inviteCodeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(17,
CGRectGetMinY(self.inviteCodeField.frame)+10,
20,
15)];
inviteCodeImageView.image = Image(@"login/inviteCodeIcon.png");
[self.keyboardView addSubview:inviteCodeImageView];
}
- (void)addLine {
UIView *phoneLine = [[UIView alloc]initWithFrame:CGRectMake(15,
CGRectGetMaxY(self.phoneTextField.frame),
loginPopUpSize.width-15,
1)];
phoneLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[self.keyboardView addSubview:phoneLine];
UIView *inviteLine = [[UIView alloc]initWithFrame:CGRectMake(15,
CGRectGetMaxY(self.inviteCodeField.frame),
loginPopUpSize.width-15,
1)];
inviteLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[self.keyboardView addSubview:inviteLine];
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[(MLNavigationController*)self.navigationController popViewControllerWithFlip];
}
- (void)textFieldDidChange:(UITextField *)textField {
if (textField.tag == TEXTFIELDTAG) {
[TPUserDefault instance].fogetPwdInfoBO.mail = textField.text;
}else if (textField.tag == TEXTFIELDTAG+1) {
[TPUserDefault instance].fogetPwdInfoBO.verCode = textField.text;
}
}
- (void)getInviteCode:(UIButton*)btn {
[self closeKeyBoard];
if (![TPUserDefault instance].fogetPwdInfoBO.mail || isBlankString([TPUserDefault instance].fogetPwdInfoBO.mail)) {
ShowTextMessage(@"请输入邮箱或手机号码");
return;
}
NSDictionary *dic = @{@"verType":@"3",@"mail":[TPUserDefault instance].fogetPwdInfoBO.mail};
[Remote doJsonActionWithBlock:0 requestUrl:getVerCodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if ([responseData[@"resultCode"] intValue] == 1) {
ShowTextMessage(responseData[@"resultMsg"]);
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)confirmEvent:(UIButton*)btn {
[self closeKeyBoard];
if (![TPUserDefault instance].fogetPwdInfoBO.mail || isBlankString([TPUserDefault instance].fogetPwdInfoBO.mail)) {
ShowTextMessage(@"请输入邮箱或手机号码");
return;
}
if (![TPUserDefault instance].fogetPwdInfoBO.verCode || isBlankString([TPUserDefault instance].fogetPwdInfoBO.verCode)) {
ShowTextMessage(@"请输入验证码");
return;
}
NSDictionary *dic = @{@"verType":@"3",@"mail":[TPUserDefault instance].fogetPwdInfoBO.mail,@"verCode":[TPUserDefault instance].fogetPwdInfoBO.verCode};
[Remote doJsonActionWithBlock:0 requestUrl:checkVerCodeURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
if ([responseData[@"resultCode"] intValue] == 1) {
confimPwdController *registerVC = confimPwdController.new;
[(MLNavigationController*)self.navigationController pushViewControllerWithAnimatePush:registerVC];
}
}else {
ShowTextMessage(message);
}
}];
}
- (void)keyboardWillShow:(NSNotification *)aNotification
{
if (![self.inviteCodeField isFirstResponder]) {
return;
}
//获取键盘的高度
NSDictionary *userInfo = [aNotification userInfo];
NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardRect = [aValue CGRectValue];
CGFloat keyboardHeight = keyboardRect.size.height;
if (isIOS8) {
keyboardHeight = keyboardRect.size.height;
}else {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight
|| orientation ==UIInterfaceOrientationLandscapeLeft) {
keyboardHeight = keyboardRect.size.width;
}else {
keyboardHeight = keyboardRect.size.height;
}
}
self.keyboardOffset = self.responderHeight- (CGRectGetHeight(self.keyboardView.frame)-keyboardHeight)+98;
[self.keyboardView setContentOffset:CGPointMake(0, self.keyboardOffset)];
self.keyboardView.scrollEnabled = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
|