|
//
// 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"
@interface feedbackController ()<UITextViewDelegate,UITextFieldDelegate>
@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)UIScrollView *keyboardView;
@property(nonatomic, strong)TPCustomButton *confirmBtn;
@property(nonatomic, assign)CGFloat scrollHeight;
@end
@implementation feedbackController
@synthesize feedContent;
@synthesize emailIcon;
@synthesize holderLabel;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.titleStr = @"用户反馈";
self.keyboardView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.keyboardView = [[UIScrollView alloc] initWithFrame:CGRectZero];
self.keyboardView.frame = CGRectMake(0, self.barHeight, rect_screen.size.width, rect_screen.size.height-self.barHeight);
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self.view addSubview:self.keyboardView];
[self.keyboardView addGestureRecognizer:tap];
feedContent = [[UITextView alloc] init];
feedContent.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
feedContent.layer.cornerRadius = 5;
feedContent.layer.borderWidth =1;
feedContent.delegate = self;
feedContent.font = appFont(14, NO);
feedContent.textColor = [UIColor colorWithHexString:TextGray];
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:LINECOLOR];
[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];
//增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
//增加监听,当键退出时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UITextField*)phoneTextField {
if (!_phoneTextField) {
_phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(20,
200,
rect_screen.size.width-40,
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 {
[self.view endEditing:YES];
/**
* bug:5044(【适配性】iPhone6 用户反馈,提交按钮无效,无法提交。)
*/
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(@"您的意见已反馈");
[self.navigationController popViewControllerAnimated:YES];
}else{
ShowTextMessage(message);
}
}];
}
- (void)tap:(id)send {
[self.view endEditing:YES];
}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
self.scrollHeight = CGRectGetMaxY(textView.frame);
return YES;
}
-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
return YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView {
textView.text = disable_emoji(textView.text);
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
self.scrollHeight = CGRectGetMaxY(textField.frame)+5;
return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
return YES;
}
- (void)textViewDidChange:(UITextView *)textView {
if ([textView.text isMatchedByRegex:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]"]) {
textView.text = disable_emoji(textView.text);
}
if (textView.text.length > 0) {
holderLabel.hidden = YES;
}else holderLabel.hidden = NO;
}
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
feedContent.frame = CGRectMake(20, 20, rect_screen.size.width-40, 150);
holderLabel.frame = CGRectMake(5, 5, 100, 20);
emailIcon.frame = CGRectMake(20, CGRectGetMaxY(feedContent.frame)+40, 20, 15);
self.phoneTextField.frame =CGRectMake(50, CGRectGetMaxY(feedContent.frame)+35, self.view.frame.size.width-70, 25);
self.line.frame = CGRectMake(20, CGRectGetMaxY(self.emailIcon.frame)+5, self.view.frame.size.width-40, 1);
self.confirmBtn.frame = CGRectMake(20,
CGRectGetMaxY(self.line.frame)+60,
rect_screen.size.width-40,
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.scrollHeight>(CGRectGetHeight(self.keyboardView.frame)-keyboardHeight)) {
[self.keyboardView setContentOffset:CGPointMake(0, self.scrollHeight - (CGRectGetHeight(self.keyboardView.frame)-keyboardHeight))];
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if ([textView isFirstResponder]) {
if ([[[textView textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textView textInputMode] primaryLanguage]) {
return NO;
}
}
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;
}
- (void)keyboardWillHide:(NSNotification *)notification {
[self.keyboardView setContentOffset:CGPointMake(0, 0)];
}
@end
|