123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- //
- // FKCustomerEnquiryView.m
- // FirstLink
- //
- // Created by ascii on 16/5/26.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKCustomerEnquiryView.h"
- #import "FKWindowViewManager.h"
- #import "FLProgressHUDHelper.h"
- @interface FKCustomerEnquiryView ()
- <UITextViewDelegate>
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UILabel *tipLabel;
- @property (nonatomic, strong) UIButton *starButton0;
- @property (nonatomic, strong) UIButton *starButton1;
- @property (nonatomic, strong) UIButton *starButton2;
- @property (nonatomic, strong) UIButton *starButton3;
- @property (nonatomic, strong) UIButton *starButton4;
- @property (nonatomic, assign) NSInteger score;
- @property (nonatomic, strong) UILabel *scoreDescLabel;
- @property (nonatomic, strong) NSArray *scoreDescArray;
- @property (nonatomic, strong) UITextView *messageView;
- @property (nonatomic, strong) UILabel *placeHolderLabel;
- @property (nonatomic, strong) UIButton *submitButton;
- @property (nonatomic, strong) UIButton *closeButton;
- @end
- @implementation FKCustomerEnquiryView
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.starButton0 = [self makeButtonWithTag:1];
- self.starButton1 = [self makeButtonWithTag:2];
- self.starButton2 = [self makeButtonWithTag:3];
- self.starButton3 = [self makeButtonWithTag:4];
- self.starButton4 = [self makeButtonWithTag:5];
-
- [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboardGesture:)]];
-
- [self addAllSubviews];
- [self configKeyboardEvent];
- }
- return self;
- }
- - (void)dealloc {
- [self removeKeyboardEvent];
- }
- #pragma mark - UITextFieldDelegate
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
- if ([text isEqualToString:@"\n"]) {
- [self.messageView resignFirstResponder];
- return NO;
- }
-
- if (text.length > 0) {
- self.placeHolderLabel.hidden = YES;
- }
-
- return YES;
- }
- - (void)textViewDidChange:(UITextView *)textView {
- self.placeHolderLabel.hidden = textView.text.length;
- }
- #pragma mark - Action
- - (IBAction)clickStarButton:(UIButton *)sender {
- NSArray *array = @[self.starButton0, self.starButton1, self.starButton2, self.starButton3, self.starButton4];
- for (int index = 0; index < array.count; index++) {
- UIButton *button = array[index];
- if (index <= (sender.tag - 1)) {
- [button setImage:[UIImage imageNamed:@"ScoredStar"] forState:UIControlStateNormal];
- } else {
- [button setImage:[UIImage imageNamed:@"UnScoreStar"] forState:UIControlStateNormal];
- }
- }
-
- self.score = sender.tag;
- self.scoreDescLabel.hidden = NO;
- self.scoreDescLabel.text = self.scoreDescArray[sender.tag - 1];
- }
- - (IBAction)clickSubmitButton:(id)sender {
- [self disappearFromWindow];
- }
- - (IBAction)clickCloseButton:(id)sender {
- [self.superview removeFromSuperview];
-
- [[FKWindowViewManager sharedManager] closeFloatView];
- }
- - (IBAction)closeKeyboardGesture:(id)sender {
- [self.messageView resignFirstResponder];
- }
- - (void)disappearFromWindow {
- if (self.score > 0) {
- if (self.enquirySubmitCallback) {
- NSString *summary = ([NSString stringWithFormat:@"%d", (int)self.score]);
- self.enquirySubmitCallback(summary, self.messageView.text);
- }
- [self.superview removeFromSuperview];
-
- [[FKWindowViewManager sharedManager] closeFloatView];
- } else {
- [FLProgressHUDHelper showText:@"请给客服打分" inView:self];
- }
- }
- #pragma mark - Keyboard Event
- - (void)keyboardWillShow:(NSNotification *)notification {
- [self changeFramwWithKeyboard:notification];
- }
- - (void)keyboardWillHide:(NSNotification *)notification {
- [self changeFramwWithKeyboard:notification];
- }
- - (void)changeFramwWithKeyboard:(NSNotification *)notification {
- CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
- CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGRect viewFrame = [self.window convertRect:self.messageView.frame fromView:self];
- CGFloat offset = (CGRectGetHeight(keyboardFrame) - (UISCREENHEIGH - CGRectGetMaxY(viewFrame)));
-
- CGPoint center;
- if (offset > 0) {
- center = CGPointMake(UISCREENWIDTH/2, self.center.y - offset);
- } else {
- center = CGPointMake(UISCREENWIDTH/2, UISCREENHEIGH/2);
- }
-
- UIViewAnimationOptions curve = (UIViewAnimationOptions)[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
- [UIView animateWithDuration:duration delay:0 options:curve animations:^{
- self.center = center;
- } completion:^(BOOL finished) {
-
- }];
- }
- #pragma mark - Method
- - (void)configKeyboardEvent {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- }
- - (void)removeKeyboardEvent {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.top.equalTo(self);
- make.size.mas_equalTo(CGSizeMake(275, 370));
- }];
-
- [self.bgView addSubview:self.headImgView];
- [self.headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgView);
- make.top.equalTo(self.bgView).offset(23);
- make.size.mas_equalTo(CGSizeMake(50, 50));
- }];
-
- [self.bgView addSubview:self.tipLabel];
- [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgView);
- make.top.equalTo(self.headImgView.mas_bottom).offset(8);
- }];
-
- [self.bgView addSubview:self.starButton2];
- [self.starButton2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgView);
- make.top.equalTo(self.tipLabel.mas_bottom).offset(6);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
-
- [self.bgView addSubview:self.starButton1];
- [self.starButton1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.starButton2);
- make.right.equalTo(self.starButton2.mas_left);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
-
- [self.bgView addSubview:self.starButton0];
- [self.starButton0 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.starButton2);
- make.right.equalTo(self.starButton1.mas_left);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
-
- [self.bgView addSubview:self.starButton3];
- [self.starButton3 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.starButton2);
- make.left.equalTo(self.starButton2.mas_right);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
-
- [self.bgView addSubview:self.starButton4];
- [self.starButton4 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.starButton2);
- make.left.equalTo(self.starButton3.mas_right);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
-
- [self.bgView addSubview:self.scoreDescLabel];
- [self.scoreDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgView);
- make.top.equalTo(self.starButton2.mas_bottom).offset(4);
- }];
-
- [self.bgView addSubview:self.messageView];
- [self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.bgView);
- make.top.equalTo(self.scoreDescLabel.mas_bottom).offset(14);
- make.size.mas_equalTo(CGSizeMake(220, 110));
- }];
-
- [self.messageView addSubview:self.placeHolderLabel];
- [self.placeHolderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.messageView).offset(5);
- make.top.equalTo(self.messageView).offset(8);
- }];
-
- [self.bgView addSubview:self.submitButton];
- [self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.bgView);
- make.height.mas_equalTo(50);
- }];
-
- [self addSubview:self.closeButton];
- [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.bgView).offset(-6);
- make.top.equalTo(self.bgView).offset(6);
- make.size.mas_equalTo(CGSizeMake(40, 40));
- }];
- }
- #pragma mark - Property
- - (UIView *)bgView {
- if (!_bgView) {
- _bgView = [UIView new];
- _bgView.clipsToBounds = YES;
- _bgView.backgroundColor = [UIColor whiteColor];
- _bgView.layer.cornerRadius = 6;
- }
- return _bgView;
- }
- - (UIImageView *)headImgView {
- if (!_headImgView) {
- _headImgView = [[UIImageView alloc] init];
- _headImgView.layer.cornerRadius = 3;
- _headImgView.clipsToBounds = YES;
- _headImgView.contentMode = UIViewContentModeScaleAspectFit;
- }
- return _headImgView;
- }
- - (UILabel *)tipLabel {
- if (!_tipLabel) {
- _tipLabel = [[UILabel alloc]init];
- _tipLabel.font = [UIFont systemFontOfSize:14];
- _tipLabel.textColor = UIColorFromRGB(0x666666);
- _tipLabel.textAlignment = NSTextAlignmentCenter;
- _tipLabel.text = @"请对本次服务评分";
- }
- return _tipLabel;
- }
- - (UIButton *)makeButtonWithTag:(NSInteger)tag {
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- button.tag = tag;
-
- [button setImage:[UIImage imageNamed:@"UnScoreStar"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(clickStarButton:) forControlEvents:UIControlEventTouchUpInside];
-
- return button;
- }
- - (UILabel *)scoreDescLabel {
- if (!_scoreDescLabel) {
- _scoreDescLabel = [[UILabel alloc] init];
- _scoreDescLabel.font = [UIFont systemFontOfSize:13];
- _scoreDescLabel.textColor = UIColorFromRGB(0xff6362);
- _scoreDescLabel.textAlignment = NSTextAlignmentCenter;
- _scoreDescLabel.hidden = YES;
- }
- return _scoreDescLabel;
- }
- - (NSArray*)scoreDescArray {
- if (!_scoreDescArray) {
- _scoreDescArray = @[@"非常不满意,各方面都很差",
- @"不满意,服务比较差",
- @"服务一般需要改善",
- @"较满意,但仍可改善",
- @"非常满意,无可挑剔"];
- }
- return _scoreDescArray;
- }
- - (UITextView *)messageView {
- if (!_messageView) {
- _messageView = [[UITextView alloc] init];
- _messageView.font = [UIFont systemFontOfSize:14];
- _messageView.layer.borderWidth = 1.0/[UIScreen mainScreen].scale;
- _messageView.layer.cornerRadius = 3;
- _messageView.layer.borderColor = UIColorFromRGB(0xcccccc).CGColor;
- _messageView.textColor = UIColorFromRGB(0x666666);
- _messageView.delegate = self;
- _messageView.returnKeyType = UIReturnKeyDone;
- }
- return _messageView;
- }
- - (UILabel *)placeHolderLabel {
- if (!_placeHolderLabel) {
- _placeHolderLabel = [[UILabel alloc] init];
- _placeHolderLabel.textAlignment = NSTextAlignmentLeft;
- _placeHolderLabel.font = [UIFont systemFontOfSize:14];
- _placeHolderLabel.backgroundColor = [UIColor whiteColor];
- _placeHolderLabel.textColor = UIColorFromRGB(0xcccccc);
- _placeHolderLabel.text = @"请输入留言...";
- }
- return _placeHolderLabel;
- }
- - (UIButton *)submitButton {
- if (!_submitButton) {
- _submitButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _submitButton.backgroundColor = UIColorFromRGB(0xff6362);
- [_submitButton setTitle:@"提交" forState:UIControlStateNormal];
- [_submitButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
- [_submitButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
-
- [_submitButton addTarget:self action:@selector(clickSubmitButton:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _submitButton;
- }
- - (UIButton *)closeButton {
- if (!_closeButton) {
- _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeButton setImage:[UIImage imageNamed:@"DetailPriceCloseIcon"] forState:UIControlStateNormal];
-
- [_closeButton addTarget:self action:@selector(clickCloseButton:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeButton;
- }
- @end
|