|
//
// feedbackController.m
// ThePaperHD
//
// Created by liyuan on 15/4/10.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
//********用户反馈*********
#import "feedbackController.h"
#import "MLNavigationController.h"
#import "TPCustomButton.h"
#import "KGModal.h"
@interface feedbackController ()<UITextViewDelegate>
@property(nonatomic, strong)UIButton *closeBtn;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UITextView *feedContent;
@property(nonatomic, strong)UIImageView *emailIcon;
@property(nonatomic, strong)UILabel *holderLabel;
@property(nonatomic, strong)UITextField *phoneTextField;
@property(nonatomic, strong)UIView *line;
@property(nonatomic, strong)TPCustomButton *confirmBtn;
@end
@implementation feedbackController
@synthesize feedContent;
@synthesize emailIcon;
@synthesize holderLabel;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.view.frame = CGRectMake(0, 0, settingPopSize.width, settingPopSize.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), settingPopSize.width, settingPopSize.height-80);
feedContent = [[UITextView alloc] init];
feedContent.layer.cornerRadius = 5;
feedContent.layer.borderWidth =1;
feedContent.delegate = self;
feedContent.font = appFont(14, NO);
feedContent.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor;
feedContent.keyboardAppearance = UIKeyboardAppearanceDefault;
if ([[TPUserDefault instance].isNightMode intValue] > 0) {
feedContent.keyboardAppearance = UIKeyboardAppearanceDark;
}
[self.keyboardView addSubview:feedContent];
holderLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 20)];
holderLabel.text = @"反馈内容";
holderLabel.font = appFont(14, NO);
holderLabel.textColor = [UIColor colorWithHexString:TextGray];
[feedContent addSubview:holderLabel];
emailIcon = [[UIImageView alloc]init];
emailIcon.image = Image(@"setting/setting_listCell_feedEmail.png");
[self.keyboardView addSubview:emailIcon];
NSAttributedString* atrString = [[NSAttributedString alloc] initWithString:@"请输入邮箱/手机号码" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:LINECOLOR]}];
self.phoneTextField.attributedPlaceholder = atrString;
[self.keyboardView addSubview:self.phoneTextField];
[self.keyboardView addSubview:self.line];
[self.keyboardView addSubview:self.confirmBtn];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[KGModal sharedInstance].tapOutsideToDismiss = NO;
__weak typeof(self) Self = self;
[[KGModal sharedInstance] setTapHandler:^{
[Self closeKeyBoard];
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (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;
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[(MLNavigationController*)self.navigationController popViewControllerWithFlip];
}
- (UITextField*)phoneTextField {
if (!_phoneTextField) {
_phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(50,
115/2,
settingPopSize.width-50-15,
35)];
_phoneTextField.backgroundColor = [UIColor clearColor];
_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.font = appFont(18, NO);
_phoneTextField.delegate = self;
}
return _phoneTextField;
}
-(UIView*)line{
if (!_line) {
_line = [[UIView alloc] init];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
-(UIButton *)confirmBtn{
if (!_confirmBtn) {
_confirmBtn = [[TPCustomButton alloc]init];
_confirmBtn.title = @"提交";
[_confirmBtn addTarget:self action:@selector(confirmEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _confirmBtn;
}
- (void)confirmEvent:(UIButton*)btn {
NSDictionary *dict = @{@"suggest":feedContent.text?feedContent.text:@"",
@"email":self.phoneTextField.text?self.phoneTextField.text:@""};
[Remote doJsonActionWithBlock:1 requestUrl:userSuggestURL parameter:dict withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
ShowTextMessage(@"您的意见已反馈");
[(MLNavigationController*)self.navigationController popViewControllerWithFlip];
}else{
ShowTextMessage(message);
}
}];
}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
CGRect textRect = feedContent.frame;
self.responderHeight = textRect.origin.y+textRect.size.height;
return YES;
}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
self.responderHeight = 0;
return YES;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
CGRect textRect = self.phoneTextField.frame;
self.responderHeight = textRect.origin.y+textRect.size.height+120;
return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
self.responderHeight = 0;
return YES;
}
- (void)textViewDidChange:(UITextView *)textView {
if (textView.text.length > 0) {
holderLabel.hidden = YES;
}else holderLabel.hidden = NO;
}
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
feedContent.frame = CGRectMake(10, 140-80, settingPopSize.width-20, 240);
holderLabel.frame = CGRectMake(5, 5, 100, 20);
emailIcon.frame = CGRectMake(10, CGRectGetMaxY(feedContent.frame)+55, 20, 15);
self.phoneTextField.frame =CGRectMake(40, CGRectGetMaxY(feedContent.frame)+50, self.view.frame.size.width-50, 25);
self.line.frame = CGRectMake(10, CGRectGetMaxY(self.phoneTextField.frame)+10, self.view.frame.size.width-20, 1);
self.confirmBtn.frame = CGRectMake(190/2,
CGRectGetMaxY(self.line.frame)+70,
settingPopSize.width-190,
40);
}
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//获取键盘的高度
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;
}
}
if (self.responderHeight>(CGRectGetHeight(self.keyboardView.frame)-keyboardHeight)) {
self.keyboardOffset = self.responderHeight- (CGRectGetHeight(self.keyboardView.frame)-keyboardHeight);
[self.keyboardView setContentOffset:CGPointMake(0, self.keyboardOffset)];
}
}
@end
|