热更新demo

creatTopicController.m 60KB

    // // creatTopicController.m // ThePaperHD // // Created by scar1900 on 15/4/28. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "creatTopicController.h" #import "AsyncImageView.h" #import "MLImageCrop.h" #import "UIImage-Extensions.h" #import "CateView.h" #define LINE_VIEW_TAG 10086 #define NAME_LABEL_TAG 10087 #define DOT_LABEL_TAG 10088 #define LINE_VIEW_TAG2 10089 #define LINE_VIEW_TAG3 10090 #define ASK_ME_LABEL 10091 #define SHOW_LABEL_TAG 10092 #define LIMIT_LANEL_TAG 10093 #define SET_PHOTO_LABEL 10094 #define IMAGE_WIDTH (rect_screen.size.width-40) #define IMAGE_HEIGHT 210*rect_screen.size.width/320 @interface creatTopicController () <UITextViewDelegate,UIActionSheetDelegate, UIImagePickerControllerDelegate,MLImageCropDelegate,UITextFieldDelegate,UINavigationControllerDelegate,UITextFieldDelegate,CateViewDelegate> { NSInteger pickerIndex; CGFloat responderHeight; CGFloat keyboardOffset; BOOL isSetPic; } @property (nonatomic, strong) NSMutableArray *cateList; @property (nonatomic, strong) UIScrollView *scrollView; @property (nonatomic, strong) UIView *selectKindView; @property (nonatomic, strong) UILabel *kindSelectLabel; //请选择 @property (nonatomic, strong) UILabel *kindLabel; //分类 @property (nonatomic, strong) UIButton *downButton; @property (nonatomic, strong) UIButton *selectBackButton; @property (nonatomic, strong) UITextView *descTextView; @property (nonatomic, strong) RTLabel *descPlacehoder; @property (nonatomic, strong) UIView *descScrollView;; @property (nonatomic, strong) UITextView *messageTextView; @property (nonatomic, strong) RTLabel *messagePlacehoder; @property (nonatomic, strong) UIView *messageView;; @property (nonatomic, strong) UIButton *addPhotoButton; @property (nonatomic, strong) AsyncImageView *topicBackImageView; @property (nonatomic, strong) UIButton *deleteImageBtn; @property (nonatomic, strong) UIImage *topicBackImg; @property (nonatomic, strong) TPCustomButton *confirmBtn; @property (nonatomic, strong) UIActionSheet *actionSheet; @property (nonatomic, strong) TopicInfoBO *topicInfo; @property (nonatomic, strong) UITextField *nameTextField; @property (nonatomic, strong) UITextField *topicTextView; @property (nonatomic, strong) UIView *topMaskView; @property (nonatomic, strong) CateView *cateView; @property (nonatomic, strong) UIButton *putButton; @property (nonatomic, strong) UILabel *chineseLabel; @property (nonatomic, strong) UILabel *englishLabel; @property (nonatomic, strong) UILabel *promptLabel; @end @implementation creatTopicController - (void)viewDidLoad { [super viewDidLoad]; [MobClick event:@"72"]; //增加监听,当键盘出现或改变时收出消息 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; //增加监听,当键退出时收出消息 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; if (!self.topicInfo) { self.topicInfo = TopicInfoBO.new; } ((MLNavigationController *)self.navigationController).canDragBack = NO; self.titleStr = @"创建话题"; self.selfLineView.hidden = YES; [self.view addSubview:self.scrollView]; [self.selectKindView addSubview:self.chineseLabel]; [self.selectKindView addSubview:self.englishLabel]; [self.selectKindView addSubview:self.kindLabel]; [self.selectKindView addSubview:self.kindSelectLabel]; [self.selectKindView addSubview:self.downButton]; [self.selectKindView addSubview:self.selectBackButton]; self.putButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self.putButton addTarget:self action:@selector(putButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [self.scrollView addSubview:self.putButton]; UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectZero]; lineView1.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; lineView1.tag = LINE_VIEW_TAG; [self.scrollView addSubview:lineView1]; isSetPic = NO; // UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectZero]; // nameLabel.text = @"我是"; // nameLabel.textColor = [UIColor colorWithHexString:TextBlack]; // nameLabel.font = appFont(14, NO); // nameLabel.textAlignment = NSTextAlignmentLeft; // nameLabel.tag = NAME_LABEL_TAG; // [self.scrollView addSubview:nameLabel]; UILabel *dotLabel = [[UILabel alloc] initWithFrame:CGRectZero]; dotLabel.text = @","; dotLabel.textColor = [UIColor colorWithHexString:TextBlack]; dotLabel.font = appFont(14, NO); dotLabel.textAlignment = NSTextAlignmentCenter; dotLabel.tag = DOT_LABEL_TAG; [self.scrollView addSubview:dotLabel]; UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectZero]; lineView2.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; lineView2.tag = LINE_VIEW_TAG2; [self.scrollView addSubview:lineView2]; UIView *lineView3 = [[UIView alloc] initWithFrame:CGRectZero]; lineView3.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; lineView3.tag = LINE_VIEW_TAG3; [self.scrollView addSubview:lineView3]; UILabel *askMeLabel = [[UILabel alloc] initWithFrame:CGRectZero]; askMeLabel.text = @",问我吧!"; askMeLabel.textColor = [UIColor colorWithHexString:TextBlack]; askMeLabel.font = appFont(14, NO); askMeLabel.textAlignment = NSTextAlignmentCenter; askMeLabel.tag = ASK_ME_LABEL; [self.scrollView addSubview:askMeLabel]; UILabel *showLabel = [[UILabel alloc] initWithFrame:CGRectZero]; showLabel.text = @"例如:我是澎湃记者李磊,关于暗访的问题,问我吧!"; showLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; showLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); showLabel.textAlignment = NSTextAlignmentLeft; showLabel.tag = SHOW_LABEL_TAG; [self.scrollView addSubview:showLabel]; UILabel *limitLabel = [[UILabel alloc] initWithFrame:CGRectZero]; limitLabel.text = @"不超过40个字"; limitLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; limitLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); limitLabel.textAlignment = NSTextAlignmentLeft; limitLabel.tag = LIMIT_LANEL_TAG; [self.scrollView addSubview:limitLabel]; [self.scrollView addSubview:self.descScrollView]; [self.descScrollView addSubview:self.descTextView]; [self.descScrollView addSubview:self.descPlacehoder]; [self.scrollView addSubview:self.messageView]; [self.messageView addSubview:self.messageTextView]; [self.messageView addSubview:self.messagePlacehoder]; [self.scrollView addSubview:self.addPhotoButton]; UILabel *addPhotoLabel = [[UILabel alloc] initWithFrame:CGRectZero]; addPhotoLabel.text = @"设置封面(可选)"; addPhotoLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; addPhotoLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); addPhotoLabel.textAlignment = NSTextAlignmentLeft; addPhotoLabel.tag = SET_PHOTO_LABEL; [self.scrollView addSubview:addPhotoLabel]; // [self.scrollView addSubview:self.topicPlaceHoder]; [self.scrollView addSubview:self.topicBackImageView]; [self.scrollView addSubview:self.promptLabel]; [self.scrollView addSubview:self.confirmBtn]; [self.scrollView addSubview:self.deleteImageBtn]; [self.scrollView addSubview:self.nameTextField]; // [self.scrollView addSubview:self.topicTextField1]; // [self.scrollView addSubview:self.topicTextField2]; [self.scrollView addSubview:self.topicTextView]; [self.scrollView addSubview:self.selectKindView]; [self askCategoryList]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; [self.scrollView addGestureRecognizer:tap]; [self subLayoutSubViews]; } - (void)subLayoutSubViews { [self.scrollView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view); make.right.equalTo(self.view); make.bottom.equalTo(self.view); make.top.equalTo(self.view).offset(self.barHeight); }]; [self.selectKindView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.scrollView).offset(20); make.top.equalTo(self.scrollView).offset(20); make.width.mas_equalTo(rect_screen.size.width-40); make.height.mas_equalTo(35); }]; [self.downButton makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.selectKindView.right).offset(-10); make.centerY.equalTo(self.selectKindView); make.size.mas_equalTo(CGSizeMake(15, 10)); }]; [self.chineseLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.selectKindView).offset(2); make.centerX.equalTo(self.selectKindView); make.size.mas_equalTo(CGSizeMake(150, 18)); }]; [self.englishLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.chineseLabel.bottom).offset(2); make.centerX.equalTo(self.selectKindView); make.size.mas_equalTo(CGSizeMake(150, 10)); }]; [self.kindLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.selectKindView); make.width.mas_equalTo(50); make.top.equalTo(self.selectKindView).offset(8.5); make.height.equalTo(@18); }]; [self.kindSelectLabel makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.selectKindView); make.centerY.equalTo(self.selectKindView); make.width.mas_equalTo(100); make.height.mas_equalTo(13); }]; [self.selectBackButton makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.selectKindView); }]; UIView *lineView1 = [self.scrollView viewWithTag:LINE_VIEW_TAG]; [lineView1 makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.selectKindView); make.top.equalTo(self.selectKindView.bottom).offset(35); make.right.equalTo(self.selectKindView).offset(-18); make.height.mas_equalTo(1); }]; [self.nameTextField makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView1); make.right.equalTo(lineView1); make.bottom.equalTo(lineView1.top).offset(-3); make.height.mas_equalTo(17); }]; // UILabel *nameLabel = (UILabel *)[self.scrollView viewWithTag:NAME_LABEL_TAG]; // [nameLabel makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(lineView1); // make.width.mas_equalTo(30); // make.bottom.equalTo(lineView1.top).offset(-3); // make.height.mas_equalTo(16); // }]; UILabel *dotLabel = (UILabel *)[self.scrollView viewWithTag:DOT_LABEL_TAG]; [dotLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView1.right); make.width.mas_equalTo(18); make.bottom.equalTo(lineView1.top).offset(-3); make.height.mas_equalTo(18); }]; UIView *lineView2 = [self.scrollView viewWithTag:LINE_VIEW_TAG2]; [lineView2 makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView1); make.top.equalTo(lineView1.bottom).offset(30); make.right.equalTo(self.selectKindView); make.height.mas_equalTo(1); }]; // [self.topicPlaceHoder makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(lineView1); // make.top.equalTo(lineView1.bottom).offset(10); // make.size.mas_equalTo(CGSizeMake(120, 16)); // }]; // [self.topicTextField1 makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(lineView1); // make.right.equalTo(lineView1); // make.bottom.equalTo(lineView2).offset(-5); // make.height.mas_equalTo(16); // }]; UIView *lineView3 = [self.scrollView viewWithTag:LINE_VIEW_TAG3]; [lineView3 makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView1); make.top.equalTo(lineView2.bottom).offset(30); make.right.equalTo(self.selectKindView).offset(-60); make.height.mas_equalTo(1); }]; // [self.topicTextField2 makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(lineView1); // make.right.equalTo(lineView3); // make.bottom.equalTo(lineView3).offset(-5); // make.height.mas_equalTo(16); // }]; [self.putButton makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView1); make.right.equalTo(lineView3); make.top.equalTo(lineView2.bottom); make.bottom.equalTo(lineView3.top); }]; [self.topicTextView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView2); make.right.equalTo(lineView2); make.bottom.equalTo(lineView2.top).offset(-3); make.height.mas_equalTo(17); }]; /** * bug:4993(创建话题页,在前两个输入栏输入的长字母下面有一部分显示不出来) */ UILabel *askMeLabel = (UILabel *)[self.scrollView viewWithTag:ASK_ME_LABEL]; [askMeLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView3.right); make.bottom.equalTo(lineView3.top).offset(-3); make.right.equalTo(self.selectKindView).offset(10); make.height.mas_equalTo(18); }]; UILabel *showLabel = (UILabel *)[self.scrollView viewWithTag:SHOW_LABEL_TAG]; [showLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView3.left); make.top.equalTo(lineView3.top).offset(15); make.right.equalTo(self.selectKindView); make.height.mas_equalTo(12); }]; UILabel *limitLabel = (UILabel *)[self.scrollView viewWithTag:LIMIT_LANEL_TAG]; [limitLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(lineView3.left); make.top.equalTo(showLabel.bottom).offset(3); make.right.equalTo(self.selectKindView); make.height.mas_equalTo(12); }]; [self.descScrollView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(limitLabel.bottom).offset(15); make.left.equalTo(limitLabel); make.right.equalTo(limitLabel); make.height.mas_equalTo(125); }]; [self.descTextView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.descScrollView); make.left.equalTo(self.descScrollView).offset(5); make.right.equalTo(self.descScrollView).offset(-5); make.height.mas_equalTo(105); }]; [self.descPlacehoder makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.descTextView).offset(5); make.right.equalTo(self.descTextView).offset(-5); make.top.equalTo(self.descTextView).offset(5); make.height.mas_equalTo(50); }]; [self.messageView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.descScrollView); make.right.equalTo(self.descScrollView); make.top.equalTo(self.descScrollView.bottom).offset(15); make.height.mas_equalTo(125); }]; [self.messageTextView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.messageView); make.left.equalTo(self.messageView).offset(5); make.right.equalTo(self.messageView).offset(-5); make.height.mas_equalTo(125-20); }]; [self.messagePlacehoder makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.messageTextView).offset(5); make.right.equalTo(self.messageTextView).offset(-5); make.top.equalTo(self.messageTextView).offset(5); make.height.mas_equalTo(100); }]; [self.addPhotoButton makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.messageView); make.top.equalTo(self.messageView.bottom).offset(10); make.size.mas_equalTo(CGSizeMake(40, 40)); }]; UILabel *addPhotoLabel = (UILabel *)[self.scrollView viewWithTag:SET_PHOTO_LABEL]; [addPhotoLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.addPhotoButton); make.top.equalTo(self.addPhotoButton.bottom).offset(5); make.right.equalTo(self.selectKindView); make.height.mas_equalTo(13); }]; [self.topicBackImageView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.addPhotoButton.bottom).offset(30); make.left.equalTo(self.addPhotoButton); make.size.mas_equalTo(CGSizeZero); }]; [self.promptLabel makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.topicBackImageView.bottom).offset(15); make.left.equalTo(self.addPhotoButton); make.right.equalTo(self.messageView); make.height.mas_equalTo(14); }]; [self.confirmBtn makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.promptLabel.bottom).offset(15); make.left.equalTo(self.addPhotoButton); make.right.equalTo(self.messageView); make.height.mas_equalTo(40); }]; } -(void)setTag:(NSString *)tagIndex{ _tag = tagIndex; } - (void)putButtonClick:(id)sender { [self.topicTextView becomeFirstResponder]; } - (void)setTopicInfo:(TopicInfoBO *)topic { _topicInfo = topic; [self.cateList enumerateObjectsUsingBlock:^(categoryBO* obj, NSUInteger idx, BOOL *stop) { if ([obj.category isEqualToString:topic.category]) { self.kindSelectLabel.text = topic.categoryName; } }]; self.descTextView.text = topic.desc; if (isBlankString(topic.desc)) { self.descPlacehoder.hidden = NO; }else self.descPlacehoder.hidden = YES; self.messageTextView.text = topic.message; if (isBlankString(topic.message)) { self.messagePlacehoder.hidden = NO; }else self.messagePlacehoder.hidden = YES; NSArray *array = [topic.title componentsSeparatedByString:@","]; if (array.count > 0) { NSString *str = array[0]; self.nameTextField.text = str; __block NSString *titleStr = @""; [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if (idx != 0 && idx != array.count-1) { titleStr = [titleStr stringByAppendingString:obj]; } }]; self.topicTextView.text = titleStr; // self.topicPlaceHoder.hidden = YES; } if (!isBlankString(topic.pic)) { self.topicBackImageView.imageUrl = topic.pic; self.topicBackImageView.imageId = getImageNameFromURL(topic.pic); [self.scrollView addSubview:self.deleteImageBtn]; CGRect rect = self.topicBackImageView.frame; rect.size = CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT); self.topicBackImageView.frame = rect; rect = self.promptLabel.frame; rect.origin.y = CGRectGetMaxY(self.topicBackImageView.frame)+15; self.promptLabel.frame = rect; self.topicInfo.imageId = @""; [self viewDidLayoutSubviews]; [self.topicBackImageView remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.addPhotoButton.bottom).offset(30); make.left.equalTo(self.addPhotoButton); make.size.mas_equalTo(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT)); }]; [self.deleteImageBtn makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.topicBackImageView).offset(5); make.top.equalTo(self.topicBackImageView).offset(-5); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; } } - (UIView *)selectKindView { if (nil == _selectKindView) { _selectKindView = [[UIView alloc] initWithFrame:CGRectZero]; _selectKindView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _selectKindView.layer.borderWidth = 1; _selectKindView.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; } return _selectKindView; } - (RTLabel *)descPlacehoder { if (nil == _descPlacehoder) { _descPlacehoder = [[RTLabel alloc] initWithFrame:CGRectZero]; _descPlacehoder.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _descPlacehoder.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _descPlacehoder.text = @"请详细描述你的话题\n(内容为4-800个字)"; _descPlacehoder.lineBreakMode = RTTextLineBreakModeCharWrapping; _descPlacehoder.lineSpacing = 5; _descPlacehoder.userInteractionEnabled = NO; } return _descPlacehoder; } - (UILabel *)promptLabel { if (_promptLabel == nil) { _promptLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _promptLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _promptLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _promptLabel.text = @"您的话题问答授权澎湃新闻使用"; _promptLabel.textAlignment = NSTextAlignmentCenter; } return _promptLabel; } - (TPCustomButton*)confirmBtn { if (!_confirmBtn) { _confirmBtn = [[TPCustomButton alloc]initWithFrame:CGRectMake(0, 0, 50, 50)]; _confirmBtn.title = @"提 交"; _confirmBtn.layer.cornerRadius = 4; _confirmBtn.clipsToBounds = YES; [_confirmBtn addTarget:self action:@selector(confirmEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _confirmBtn; } - (UITextView *)descTextView { if (nil == _descTextView) { _descTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; _descTextView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _descTextView.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _descTextView.textAlignment = NSTextAlignmentLeft; _descTextView.textColor = [UIColor colorWithHexString:TextGray]; _descTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _descTextView.delegate = self; } return _descTextView; } - (UIView *)descScrollView { if (nil == _descScrollView) { _descScrollView = [[UIView alloc] initWithFrame:CGRectZero]; _descScrollView.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; _descScrollView.layer.borderWidth = 1; _descScrollView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _descScrollView.layer.cornerRadius = 2; _descScrollView.clipsToBounds = YES; } return _descScrollView; } - (RTLabel *)messagePlacehoder { if (nil == _messagePlacehoder) { _messagePlacehoder = [[RTLabel alloc] initWithFrame:CGRectZero]; _messagePlacehoder.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _messagePlacehoder.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _messagePlacehoder.text = @"(可选)还可以给小编留言哦,详细描述您的通讯方式和作答时间等信息,可以帮助更快审核通过\n(不超过800个字,仅小编可见)"; _messagePlacehoder.lineBreakMode = RTTextLineBreakModeCharWrapping; _messagePlacehoder.lineSpacing = 5; _messagePlacehoder.userInteractionEnabled = NO; } return _messagePlacehoder; } - (UILabel *)chineseLabel { if (_chineseLabel == nil) { _chineseLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _chineseLabel.font = appFont(16, NO); _chineseLabel.textColor = [UIColor colorWithHexString:TextBlack]; _chineseLabel.textAlignment = NSTextAlignmentCenter; } return _chineseLabel; } - (UILabel *)englishLabel { if (nil == _englishLabel) { _englishLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _englishLabel.font = appFont(8, NO); _englishLabel.textColor = [UIColor colorWithHexString:TextBlack]; _englishLabel.textAlignment = NSTextAlignmentCenter; } return _englishLabel; } - (UITextView *)messageTextView { if (nil == _messageTextView) { _messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; _messageTextView.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _messageTextView.textAlignment = NSTextAlignmentLeft; _messageTextView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _messageTextView.textColor = [UIColor colorWithHexString:TextGray]; _messageTextView.autoresizingMask = UIViewAutoresizingFlexibleHeight; _messageTextView.delegate = self; } return _messageTextView; } - (UIView *)messageView { if (nil == _messageView) { _messageView = [[UIView alloc] initWithFrame:CGRectZero]; _messageView.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; _messageView.layer.borderWidth = 1; _messageView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _messageView.layer.cornerRadius = 2; _messageView.clipsToBounds = YES; } return _messageView; } - (UITextField *)nameTextField { if (nil == _nameTextField) { _nameTextField = [[UITextField alloc] initWithFrame:CGRectZero]; _nameTextField.font = appFont(14, NO); _nameTextField.delegate = self; _nameTextField.textColor = [UIColor colorWithHexString:TextBlack]; _nameTextField.textAlignment = NSTextAlignmentLeft; _nameTextField.autoresizingMask = UIViewAutoresizingFlexibleWidth; _nameTextField.text = @"我是"; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(selfIntroDidChange:) name:UITextFieldTextDidChangeNotification object:_nameTextField]; } return _nameTextField; } - (UIScrollView *)scrollView { if (_scrollView == nil) { _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; _scrollView.clipsToBounds = YES; _scrollView.delegate = self; _scrollView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; } return _scrollView; } - (UIView *)topMaskView { if (nil == _topMaskView) { _topMaskView = [[UIView alloc] initWithFrame:CGRectZero]; _topMaskView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; } return _topMaskView; } - (UILabel *)kindLabel { if (nil == _kindLabel) { _kindLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _kindLabel.text = @"分类"; _kindLabel.font = appFont(TEXT_THREE_LEVELSIZE, NO); _kindLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _kindLabel.textAlignment = NSTextAlignmentCenter; } return _kindLabel; } - (UILabel *)kindSelectLabel { if (nil == _kindSelectLabel) { _kindSelectLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _kindSelectLabel.text = @"请选择"; _kindSelectLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _kindSelectLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _kindSelectLabel.textAlignment = NSTextAlignmentCenter; } return _kindSelectLabel; } - (UIButton *)downButton { if (nil == _downButton) { _downButton = [UIButton buttonWithType:UIButtonTypeCustom]; _downButton.userInteractionEnabled = NO; if ([[TPUserDefault instance].isNightMode integerValue] == 1) { [_downButton setImage:Image(@"Button/DownIcon_night.png") forState:UIControlStateNormal]; }else{ [_downButton setImage:Image(@"Button/DownIcon.png") forState:UIControlStateNormal]; } } return _downButton; } - (UIButton *)selectBackButton { if (nil == _selectBackButton) { _selectBackButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_selectBackButton addTarget:self action:@selector(selectButtonClick:) forControlEvents:UIControlEventTouchUpInside]; } return _selectBackButton; } - (UIButton *)addPhotoButton { if (nil == _addPhotoButton) { _addPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_addPhotoButton setImage:Image(@"topic/addPhoto.png") forState:UIControlStateNormal]; [_addPhotoButton addTarget:self action:@selector(addPhotoButtonClick:) forControlEvents:UIControlEventTouchUpInside]; } return _addPhotoButton; } - (AsyncImageView*)topicBackImageView { if (!_topicBackImageView) { _topicBackImageView = [[AsyncImageView alloc]initWithFrame:CGRectZero]; _topicBackImageView.isHaveWaterPrint = NO; } return _topicBackImageView; } - (UIButton*)deleteImageBtn { if (!_deleteImageBtn) { _deleteImageBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _deleteImageBtn.frame = CGRectZero; [_deleteImageBtn setImage:Image(@"Button/delete.png") forState:UIControlStateNormal]; [_deleteImageBtn setImage:Image(@"Button/delete_s.png") forState:UIControlStateHighlighted]; [_deleteImageBtn addTarget:self action:@selector(deleteImage:) forControlEvents:UIControlEventTouchUpInside]; } return _deleteImageBtn; } - (UITextField *)topicTextView { if (nil == _topicTextView) { _topicTextView = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, rect_screen.size.width-40, 100)]; _topicTextView.textColor = [UIColor colorWithHexString:TextBlack]; _topicTextView.autoresizingMask = UIViewAutoresizingNone; _topicTextView.font = appFont(14, NO); _topicTextView.backgroundColor = [UIColor clearColor]; _topicTextView.delegate = self; _topicTextView.placeholder = @"你想要说的话题"; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(selfIntroDidChange:) name:UITextFieldTextDidChangeNotification object:_topicTextView]; } return _topicTextView; } #pragma mark - keyBordHandler //当键盘出现或改变时调用 - (void)keyboardWillShow:(NSNotification *)aNotification { //获取键盘的高度 NSDictionary *userInfo = [aNotification userInfo]; NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]; CGRect keyboardRect = [aValue CGRectValue]; CGFloat keyboardHeight = keyboardRect.size.height; if ([self.descTextView isFirstResponder]) { responderHeight = CGRectGetMaxY(self.descScrollView.frame); }else if ([self.messageTextView isFirstResponder]) { responderHeight = CGRectGetMaxY(self.messageView.frame); } if (responderHeight < CGRectGetHeight(self.scrollView.frame)-keyboardHeight) { return; } CGFloat offset = CGRectGetHeight(self.scrollView.frame)-keyboardHeight; if (responderHeight > offset) { keyboardOffset = responderHeight - offset + 50; [self.scrollView setContentOffset:CGPointMake(0, keyboardOffset)]; } } //当键退出时调用 - (void)keyboardWillHide:(NSNotification *)aNotification { CGPoint currentOffset = self.scrollView.contentOffset; currentOffset.y = currentOffset.y - keyboardOffset; [self.scrollView setContentOffset:currentOffset]; keyboardOffset = 0; } #pragma mark - ButtonHandler - (void)selectButtonClick:(UIButton *)sender { [self tap:nil]; if (!sender.selected) { self.cateView.hidden = NO; CGRect rect = self.cateView.frame; rect.origin.y = CGRectGetMaxY(self.selectKindView.frame)-3; [UIView animateWithDuration:0.35 animations:^{ self.cateView.frame = rect; self.downButton.transform = CGAffineTransformRotate(self.downButton.transform, M_PI); } completion:^(BOOL finished) { sender.selected = !sender.selected; }]; }else { CGRect rect = self.cateView.frame; rect.origin.y -= rect.size.height; [UIView animateWithDuration:0.35 animations:^{ self.cateView.frame = rect; self.downButton.transform = CGAffineTransformRotate(self.downButton.transform, -M_PI); } completion:^(BOOL finished) { sender.selected = !sender.selected; self.cateView.hidden = YES; }]; } } - (void)addPhotoButtonClick:(UIButton *)sender { [self showActionSheet]; } - (void)showActionSheet { if (self.actionSheet) { self.actionSheet = nil; } [self closeKeyBoard]; self.actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"相册选择",@"拍照",nil]; self.actionSheet.actionSheetStyle = UIActionSheetStyleDefault; self.actionSheet.center = self.scrollView.center; [self.actionSheet showInView:self.scrollView]; } - (void)closeKeyBoard { [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; [self.view endEditing:YES]; } - (void)selfIntroDidChange:(NSNotification*)obj {//我的话题,创建话题界面,input1和input2出现逻辑错误(bug:4808) UITextField *textField = (UITextField *)obj.object; 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.nameTextField) { NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式 if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写 UITextRange *selectedRange = [textField markedTextRange]; //获取高亮部分 UITextPosition *position; if (selectedRange) { position = [textField positionFromPosition:selectedRange.start offset:0]; }else{ position = nil; } if (!position) { int limit = 20; if (self.topicTextView.text.length > 15) { limit = 35 - (int)self.topicTextView.text.length; } if (textField.text.length > limit) { textField.text = [textField.text substringToIndex:limit]; } } }else{// 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况 int limit = 20; if (self.topicTextView.text.length > 15) { limit = 35 - (int)self.topicTextView.text.length; } if (textField.text.length > limit) { textField.text = [textField.text substringToIndex:limit]; } } }else { int limit = 20; if (self.nameTextField.text.length > 15) { limit = 35 - (int)self.nameTextField.text.length; } NSString *lang = [[UITextInputMode currentInputMode] primaryLanguage]; // 键盘输入模式 if ([lang isEqualToString:@"zh-Hans"]) { // 简体中文输入,包括简体拼音,健体五笔,简体手写 UITextRange *selectedRange = [textField markedTextRange]; //获取高亮部分 UITextPosition *position; if (selectedRange) { position = [textField positionFromPosition:selectedRange.start offset:0]; }else{ position = nil; } if (!position) { if (textField.text.length > limit) { textField.text = [textField.text substringToIndex:limit]; } } }else{// 中文输入法以外的直接对其统计限制即可,不考虑其他语种情况 if(textField.text.length >limit){ textField.text = [textField.text substringToIndex:limit]; } } } NSString *intro = self.nameTextField.text; NSString *topicTit = self.topicTextView.text; NSString *title = [NSString stringWithFormat:@"%@,%@,问我吧!",intro,topicTit]; self.topicInfo.title = title; } - (void)deleteImage:(UIButton*)btn { [self.topicBackImageView remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.addPhotoButton.bottom).offset(30); make.left.equalTo(self.addPhotoButton); make.size.mas_equalTo(CGSizeZero); }]; isSetPic = YES; CGRect rect = self.topicBackImageView.frame; rect.size = CGSizeZero; self.topicBackImageView.frame = rect; rect = self.promptLabel.frame; rect.origin.y = CGRectGetMaxY(self.topicBackImageView.frame)+15; self.promptLabel.frame = rect; [UIView animateWithDuration:0.3 animations:^{ [self.deleteImageBtn removeFromSuperview]; _deleteImageBtn = nil; self.confirmBtn.frame = rect; self.topicInfo.imageId = @"-1"; [self viewDidLayoutSubviews]; } completion:^(BOOL finished) { }]; } - (void)confirmEvent:(UIButton*)btn { [self closeKeyBoard]; if (isBlankString(self.topicInfo.category)) { ShowTextMessage(@"必填项不能为空"); return; } if (self.nameTextField.text.length + self.topicTextView.text.length >35) { ShowTextMessage(@"话题标题过长,请重新输入!"); return; } NSString *intro = self.nameTextField.text; NSString *topicTit = self.topicTextView.text; if (isBlankString(intro) || isBlankString(topicTit)) { ShowTextMessage(@"必填项不能为空"); return; } NSString *title = [NSString stringWithFormat:@"%@,%@,问我吧!",intro,topicTit]; /** * bug:5100(创建话题:标题“我是”会显示2次) */ self.topicInfo.title = title; if (isBlankString(self.descTextView.text)) { ShowTextMessage(@"必填项不能为空"); return; } if (self.descTextView.text.length < 4) { ShowTextMessage(@"话题描述少于4个字!"); return; } if (self.messageTextView.text.length > 800) { ShowTextMessage(@"话题描述大于800个字!"); return; } self.topicInfo.desc = self.descTextView.text; self.topicInfo.message = self.messageTextView.text; if (!_tag ||[_tag isEqualToString:@"0"]) { NSMutableDictionary *dic = setDataModelToDic(self.topicInfo, [TopicInfoBO class]); [dic setValue:self.topicInfo.desc forKey:@"description"]; __weak typeof(self) Self = self; if (self.topicBackImg && isBlankString(self.topicInfo.imageId)) { [self uploadImage:self.topicBackImg success:^(NSString *imageID) { [self stopHud]; [dic setValue:imageID forKey:@"imageId"]; [Remote doJsonActionWithBlock:0 requestUrl:saveTopicURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { [self showHUDText]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [Self.navigationController popViewControllerAnimated:YES]; [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERCREATTOPIC object:nil]; }); }else { ShowTextMessage(message); } }]; }]; }else { [dic setValue:self.topicInfo.imageId forKey:@"imageId"]; [Remote doJsonActionWithBlock:0 requestUrl:saveTopicURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { [self showHUDText]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [Self.navigationController popViewControllerAnimated:YES]; [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERCREATTOPIC object:nil]; }); }else { ShowTextMessage(message); } }]; } }else{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否确认提交话题修改?" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"放弃",nil]; alert.tag = 1002; [alert show]; }); } } - (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; } - (void)uploadImage:(UIImage *)image success:(void(^)(NSString *imageID))successful{ NSData *imgData = UIImageJPEGRepresentation(image, 0.1f); CGFloat lengh = [imgData length]; NSDictionary *dic = @{@"C_TYPE":@"jpg",@"C_LEN":[NSString stringWithFormat:@"%.f",lengh],@"O_TYPE":@"1",@"O_ID":self.topicInfo.topicId?self.topicInfo.topicId:@""}; __weak typeof(self) Self = self; // [self startHud]; [Remote upLoadImageAsyncWithBlock:getUploadURL actionTag:0 parameter:dic image:nil completion:^(BOOL success, NSString *message, id responseData) { if (success) { NSString *status = responseData[@"STATUS"]; if ([status intValue] != 1 && [status intValue] != 13) { ShowTextMessage(responseData[@"DESC"]); [Self stopHud]; return; } NSString *url = responseData[@"URL"]; NSString *fileName = responseData[@"FILE_NAME"]; SaveFile(CachePath(fileName), imgData); NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:responseData]; [dic removeObjectForKey:@"URL"]; [dic setValue:@"0" forKey:@"P_START"]; [dic setValue:dic[@"C_LEN"] forKey:@"P_END"]; [dic removeObjectForKey:@"PARAM"]; [dic removeObjectForKey:@"STATUS"]; [dic removeObjectForKey:@"RESULT"]; [Remote upLoadImageAsyncWithBlock:url actionTag:1 parameter:dic image:CachePath(fileName) completion:^(BOOL success, NSString *message, id responseData) { [Self stopHud]; if (success) { TPLOG (@"%@",responseData); NSString *status = responseData[@"STATUS"]; if ([status intValue] == 13) { // NSString *newImageURL = responseData[@"IMAGEURL"]; NSString *imageID = responseData[@"IMAGEID"]; if (successful) { successful(imageID); } }else { ShowTextMessage(message); } }else { ShowTextMessage(message); } }]; }else { ShowTextMessage(message); [Self stopHud]; } }]; } #pragma mark - remote delegate #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 0) { NSArray *tempCataList = responsData[@"dataList"]; self.cateList = [NSMutableArray array]; [tempCataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { categoryBO *cate = setJsonDicToDataModel(obj, [categoryBO class]); [self.cateList addObject:cate]; }]; [self GetCateView]; if (!self.topicBO) { self.topicInfo = TopicInfoBO.new; [self stopHud]; }else { NSDictionary *dic = @{@"topicId":self.topicBO.topicId,@"forwordType":@"7"}; [Remote doJsonAction:1 requestUrl:topicInfoURL parameter:dic delegate:self]; } }else { self.topicBO = setJsonDicToDataModel(responsData[@"topicInfo"], [TopicInfoBO class]); self.topicBO.desc = responsData[@"topicInfo"][@"description"]; NSString *newNums = responsData[@"topicInfo"][@"newNums"]; if (newNums) { self.topicBO.unNums = newNums; } TopicInfoBO *temp = setJsonDicToDataModel(responsData[@"topicInfo"], [TopicInfoBO class]); temp.desc = responsData[@"topicInfo"][@"description"]; if (newNums) { temp.unNums = newNums; } self.topicInfo = temp; [self stopHud]; } } - (void)GetCateView { if (self.cateView == nil) { int temp = (int)self.cateList.count/3; if (self.cateList.count %3 != 0) { temp++; } self.cateView = [[CateView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.selectKindView.frame)-temp*70*rect_screen.size.width/320-3, rect_screen.size.width-40, temp*70*rect_screen.size.width/320)]; self.cateView.cateListArray = self.cateList; self.cateView.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; self.cateView.layer.borderWidth = 0.5; self.cateView.layer.cornerRadius = 4; self.cateView.delegate = self; self.cateView.clipsToBounds = YES; [self.scrollView insertSubview:self.cateView belowSubview:self.selectKindView]; self.cateView.hidden = YES; [self.scrollView addSubview:self.topMaskView]; [self.topMaskView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.selectKindView); make.right.equalTo(self.selectKindView); make.bottom.equalTo(self.selectKindView.top); make.height.mas_equalTo(20); }]; } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code { ShowTextMessage(message); [self stopHud]; } #pragma mark - actionsheet delegate - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { pickerIndex = buttonIndex; } - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; // picker.navigationController.navigationBar.barTintColor = [UIColor blackColor]; // picker.navigationController.navigationBar.tintColor = [UIColor whiteColor]; // [picker.navigationController.navigationBar setTitleTextAttributes: // @{NSForegroundColorAttributeName:[UIColor whiteColor]}]; picker.delegate = self; picker.allowsEditing = NO; if (buttonIndex == 0) { picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:picker animated:YES completion:nil]; }else if (buttonIndex == 1) { picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [NSArray arrayWithObject:@"public.image"]; [self presentViewController:picker animated:YES completion:nil]; } self.actionSheet = nil; } - (void)askCategoryList { [Remote doJsonAction:0 requestUrl:getTopicCategorysURL parameter:nil delegate:self]; } #pragma mark UIImagePickerControllerDelegate - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { picker = nil; [self dismissViewControllerAnimated:YES completion:nil]; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)infos { picker = nil; [self dismissViewControllerAnimated:YES completion:nil]; [self editImage:infos]; } - (void)editImage:(NSDictionary *)infos{ NSString *mediaType = [infos objectForKey:UIImagePickerControllerMediaType]; if ([mediaType isEqualToString:@"public.image"]){ UIImage *image = [infos objectForKey:@"UIImagePickerControllerOriginalImage"]; MLImageCrop *imageCrop = [[MLImageCrop alloc]init]; self.topicInfo.imageId = @""; imageCrop.delegate = self; imageCrop.ratioOfWidthAndHeight = IMAGE_WIDTH/IMAGE_HEIGHT; imageCrop.image = image; [imageCrop showWithAnimation:YES]; }else { } } #pragma mark - cateDelegate - (void)cateButtonClickWith:(categoryBO *)cate { self.kindSelectLabel.text = @""; self.chineseLabel.text = cate.name; self.englishLabel.text = cate.enname; [self selectButtonClick:self.selectBackButton]; self.topicInfo.category = cate.category; self.topicInfo.categoryName = cate.name; } #pragma mark - crop delegate - (void)cropImage:(UIImage*)croppedImage forOriginalImage:(UIImage*)originalImage { croppedImage = [croppedImage imageByScalingProportionallyToMinimumSize:CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT)]; self.topicBackImg = croppedImage; self.topicBackImageView.imageView.image = self.topicBackImg; CGRect rect = self.topicBackImageView.frame; rect.size = CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT); self.topicBackImageView.frame = rect; rect = self.promptLabel.frame; rect.origin.y = CGRectGetMaxY(self.topicBackImageView.frame)+15; self.promptLabel.frame = rect; self.topicInfo.imageId = @""; isSetPic = YES; [self viewDidLayoutSubviews]; [self.scrollView addSubview:self.deleteImageBtn]; [self.topicBackImageView remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.addPhotoButton.bottom).offset(30); make.left.equalTo(self.addPhotoButton); make.size.mas_equalTo(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT)); }]; [self.deleteImageBtn makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.topicBackImageView).offset(5); make.top.equalTo(self.topicBackImageView).offset(-5); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; } - (void)getImageSuccess:(UIImage *)image { self.topicBackImg = image; } - (void)viewDidLayoutSubviews { self.scrollView.contentSize = CGSizeMake(0, CGRectGetMaxY(self.promptLabel.frame) +15+30+20); /** * bug:5179(4s 创建话题页面没做滚动条) */ [super viewDidLayoutSubviews]; } - (void)textFieldDidBeginEditing:(UITextField *)textField { responderHeight = CGRectGetMaxY(textField.frame); } - (void)textFieldDidEndEditing:(UITextField *)textField { } - (BOOL)textFieldShouldClear:(UITextField *)textField { return YES; } #pragma mark - UITextViewDelegate - (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 == self.descTextView) { self.topicInfo.desc = textView.text; if (textView.text.length > 0) { self.descPlacehoder.hidden = YES; if (textView.text.length >= 800) { textView.text = [textView.text substringToIndex:800]; } }else{ self.descPlacehoder.hidden = NO; } }else if (textView == self.messageTextView) { self.topicInfo.message = textView.text; if (textView.text.length > 0) { self.messagePlacehoder.hidden = YES; if (textView.text.length >= 800) { textView.text = [textView.text substringToIndex:800]; } }else{ self.messagePlacehoder.hidden = NO; } } } - (void)textViewDidEndEditing:(UITextView *)textView { textView.text = disable_emoji(textView.text); } - (void)backHandler { // [self closeKeyBoard]; [self tap:nil]; if (!_topicBO) { if (isBlankString(self.topicInfo.category) &&isBlankString(self.topicInfo.title) &&isBlankString(self.topicInfo.desc) &&isBlankString(self.topicInfo.message) &&isBlankString(self.topicInfo.imageId) &&!isSetPic) { [self.navigationController popViewControllerAnimated:YES]; }else { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否放弃已输入内容?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; alert.tag = 1003; [alert show]; }); } }else { if ([Remote IsEableNetwork]) { if ([self.topicInfo.category isEqualToString:self.topicBO.category] && [self.topicInfo.title isEqualToString:self.topicBO.title] && [self.topicInfo.desc isEqualToString:self.topicBO.desc] && [self.topicInfo.message isEqualToString:self.topicBO.message]) { if (!self.topicInfo.imageId || [self.tag isEqualToString:@"3"]) { if (isSetPic == NO) { [self.navigationController popViewControllerAnimated:YES]; }else { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否放弃已输入内容?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; alert.tag = 1004; [alert show]; }); } }else { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否放弃已输入内容?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; alert.tag = 1004; [alert show]; }); } }else { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否放弃已输入内容?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil]; alert.tag = 1001; [alert show]; }); } }else { [self.navigationController popViewControllerAnimated:YES]; } } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != 0) { if (alertView.tag == 1001 || alertView.tag == 1003 || alertView.tag == 1004){ [alertView dismissWithClickedButtonIndex:-1 animated:YES]; [self.navigationController popViewControllerAnimated:YES]; ((MLNavigationController *)self.navigationController).canDragBack = YES; } }else{ if (alertView.tag == 1002) { NSMutableDictionary *dic = setDataModelToDic(self.topicInfo, [TopicInfoBO class]); [dic setValue:self.topicInfo.desc forKey:@"description"]; [dic setValue:self.topicInfo.topicId forKey:@"topicId"]; __weak typeof(self) Self = self; if (self.topicBackImg && isBlankString(self.topicInfo.imageId)) { [self uploadImage:self.topicBackImg success:^(NSString *imageID) { [self stopHud]; [dic setValue:imageID forKey:@"imageId"]; [Remote doJsonActionWithBlock:0 requestUrl:saveTopicURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { [self showHUDText]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [Self.navigationController popViewControllerAnimated:YES]; [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERCREATTOPIC object:nil]; }); ((MLNavigationController *)self.navigationController).canDragBack = YES; }else { ShowTextMessage(message); } }]; }]; }else { [dic setValue:self.topicInfo.imageId forKey:@"imageId"]; [Remote doJsonActionWithBlock:0 requestUrl:saveTopicURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { [self showHUDText]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [Self.navigationController popViewControllerAnimated:YES]; [[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERCREATTOPIC object:nil]; }); }else { ShowTextMessage(message); } }]; } }else{ } } } - (void)textViewDidBeginEditing:(UITextView *)textView { responderHeight = CGRectGetMaxY(textView.frame); // if (textView == self.descTextView) { // self.descPlacehoder.hidden = YES; // }else if (textView == self.messageTextView) { // self.messagePlacehoder.hidden = YES; // }else if (textView == self.topicTextView) { // self.topicPlaceHoder.hidden = YES; // } } - (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; } #pragma mark - scrollViewDelegate - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [self closeKeyBoard]; } #pragma mark - tapHandler - (void)tap:(id)sender { [self.view endEditing:YES]; } #pragma mark- delloc - (void)dealloc { //增加监听,当键盘出现或改变时收出消息 // [[NSNotificationCenter defaultCenter] removeObserver:self // name:UIKeyboardWillShowNotification // object:nil]; // // //增加监听,当键退出时收出消息 // [[NSNotificationCenter defaultCenter] removeObserver:self // name:UIKeyboardWillHideNotification // object:nil]; // [[NSNotificationCenter defaultCenter] removeObserver:self // name:UITextFieldTextDidChangeNotification // object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)showHUDText { if ([self.tag isEqualToString:@"3"]) [MobClick event:@"78"]; else [MobClick event:@"65"]; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; // Configure for text only and offset down hud.mode = MBProgressHUDModeText; hud.userInteractionEnabled = NO; UIColor *hudColor = [UIColor colorWithRed:159.f/255.f green:159.f/255.f blue:159.f/255.f alpha:0.9f]; hud.color = hudColor; hud.cornerRadius = 4; hud.detailsLabelFont = appFont(TEXT_FOUR_LEVELSIZE, NO); hud.detailsLabelText = @"提交成功,审核通过后将在问吧中显示"; hud.margin = 10.f; hud.removeFromSuperViewOnHide = YES; hud.yOffset = self.view.frame.size.height/2-rect_screen.size.height/3; [hud hide:YES afterDelay:1]; } @end