IVTMyFeedBackViewController.m
10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//
// IVTMyFeedBackViewController.m
// IVTMeLiveTwo
//
// Created by XRG on 16/8/23.
// Copyright © 2016年 QLQ. All rights reserved.
//
#import "IVTMyFeedBackViewController.h"
@interface IVTMyFeedBackViewController ()<UITextViewDelegate,UITextFieldDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
{
UITextView *feedBackTextView;
UILabel *hintLabel;
UIButton *addPhotoButton;
UITextField *contactLabel;
NSData *formImageData;
}
@end
@implementation IVTMyFeedBackViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setNavigationBar];
UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 5, kScreenWidth, 183)];
headView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:headView];
feedBackTextView = [[UITextView alloc] initWithFrame:CGRectMake(25, 10, kScreenWidth-25*2, 90)];
feedBackTextView.backgroundColor = [UIColor whiteColor];
feedBackTextView.font = [UIFont YXFontOfSize:14];
feedBackTextView.textColor = [UIColor YXColorWithHexCode:@"#8C8C8C"];
feedBackTextView.delegate = self;
feedBackTextView.autocorrectionType = UITextAutocorrectionTypeNo;//不联想输入
feedBackTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;//不大小写
[headView addSubview:feedBackTextView];
hintLabel = [[UILabel alloc] initWithFrame:CGRectMake(3, 0, feedBackTextView.frame.size.width-3, 50)];
hintLabel.backgroundColor = [UIColor clearColor];
hintLabel.font = [UIFont YXFontOfSize:14];
hintLabel.textColor = [UIColor YXColorWithHexCode:@"#8C8C8C"];
hintLabel.text = @"请描述您遇到的问题的功能名称,以及问题现象,同时可以上传手机截图(必填)";
hintLabel.numberOfLines = 2;
[feedBackTextView addSubview:hintLabel];
addPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
addPhotoButton.frame = CGRectMake(28, 110, 56, 56);
[addPhotoButton setImage:[UIImage imageNamed:@"添加图片"] forState:UIControlStateNormal];
[addPhotoButton addTarget:self action:@selector(photoClick) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:addPhotoButton];
UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, kScreenWidth, 46)];
footView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:footView];
UILabel *link = [[UILabel alloc]initWithFrame:CGRectMake(28, 13, 57, 20)];
link.text = @"联系方式";
link.textColor = [UIColor IVTMainTextColor];
link.font = [UIFont YXFontOfSize:14];
[footView addSubview:link];
contactLabel = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, kScreenWidth-120, 46)];
contactLabel.font = [UIFont YXFontOfSize:14];
contactLabel.backgroundColor = [UIColor whiteColor];
contactLabel.textColor = [UIColor IVTMainTextColor];
contactLabel.placeholder =@"邮箱/QQ/手机号码(必填)";
//修改textField提示文字颜色
[contactLabel setValue:[UIColor IVTSeparatorColor] forKeyPath:@"_placeholderLabel.textColor"];
contactLabel.delegate = self;
[footView addSubview:contactLabel];
UIButton *feed = [UIButton buttonWithType:UIButtonTypeCustom];
feed.frame = CGRectMake(15, 300, kScreenWidth - 15*2, 35);
[feed setBackgroundImage:[UIImage imageNamed:@"提交反馈按钮"] forState:UIControlStateNormal];
[feed setTitle:@"提交反馈" forState:UIControlStateNormal];
[feed setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
feed.titleLabel.font = [UIFont YXFontOfSize:14];
[feed addTarget:self action:@selector(feedMessage:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:feed];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewTapped:)];
tap.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tap];
}
- (void)setNavigationBar{
self.navigationItem.title = @"意见反馈";
}
#pragma mark - textView代理
- (void)textViewDidChange:(UITextView *)textView{
if(textView.text.length == 0){
hintLabel.hidden = NO;
}else{
hintLabel.hidden = YES;
}
}
- (void)photoClick{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] && ![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"没找到摄像头" preferredStyle:UIAlertControllerStyleAlert];
[alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alertC animated:YES completion:^{
}];
}
else{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:YES completion:nil];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alert animated:YES completion:^{
}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
UIImage *imagePicker = [self imageWithImage:info[@"UIImagePickerControllerEditedImage"] scaledToSize:CGSizeMake(400, 400)];
formImageData = UIImageJPEGRepresentation(imagePicker, 0.4);
UIImage *image = [UIImage imageWithData:formImageData];
[addPhotoButton setImage:image forState:UIControlStateNormal];
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)targetSize{
UIImage *sourceImage = image;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
if (!CGSizeEqualToSize(imageSize, targetSize))
{
CGFloat widthFactor = targetWidth / width;
CGFloat heightFactor = targetHeight / height;
if (widthFactor > heightFactor)
scaleFactor = widthFactor;
else
scaleFactor = heightFactor;
scaledWidth= width * scaleFactor;
scaledHeight = height * scaleFactor;
if (widthFactor > heightFactor){
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
}
else if (widthFactor < heightFactor)
{
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
}
}
UIGraphicsBeginImageContext(targetSize);
CGRect thumbnailRect = CGRectZero;
thumbnailRect.origin = thumbnailPoint;
thumbnailRect.size.width= scaledWidth;
thumbnailRect.size.height = scaledHeight;
[sourceImage drawInRect:thumbnailRect];
newImage = UIGraphicsGetImageFromCurrentImageContext();
if(newImage == nil)
NSLog(@"could not scale image");
UIGraphicsEndImageContext();
return newImage;
}
- (void)feedMessage:(UIButton *)btn{
if (feedBackTextView.text.length > 0) {
if (contactLabel.text.length > 0) {
[HUDUtil showLoading];
btn.enabled = NO;
[[IVTNetworkAPIClient sharedClient] feedback:[feedBackTextView.text base64EncodedFromString] formData:formImageData success:^(NSDictionary *successData) {
[HUDUtil showSuccess:@"反馈成功"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} error:^(NSDictionary *successData) {
NSString *msg = successData[@"description"];
[HUDUtil showError:msg];
btn.enabled = YES;
} failure:^(NSError *failureError) {
[HUDUtil showError:@"网络异常"];
btn.enabled = YES;
}];
}
else{
[HUDUtil showError:@"请输入联系方式"];
}
}
else{
[HUDUtil showError:@"反馈不能为空"];
}
}
-(void)viewTapped:(UITapGestureRecognizer *)tap{
[self.view endEditing: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