-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendViewController.m
283 lines (202 loc) · 8.1 KB
/
SendViewController.m
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
//
// SendViewController.m
// WeiChi
//
// Created by imac on 15/9/17.
// Copyright (c) 2015年 imac. All rights reserved.
//
#import "SendViewController.h"
#import "ThemeManager.h"
#import "ThemeButton.h"
#import "MMDrawerController.h"
//#import "DataService.h"
@interface SendViewController ()
@end
@implementation SendViewController{
UIImage *_sendImage;
}
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self _createNavItems];
[self _createEditorViews];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear: animated ];
//弹出键盘
[_textView becomeFirstResponder];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//导航栏不透明,当导航栏不透明的时候 ,子视图的y的0位置在导航栏下面
self.navigationController.navigationBar.translucent = NO;
_textView.frame = CGRectMake(0, 0, kScreenWidth, 120);
//设置textView 内容偏移
_textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
//弹出键盘
[_textView becomeFirstResponder];
}
#pragma mark - 创建子视图
- (void)_createNavItems{
//1.关闭按钮
ThemeButton *closeButton = [[ThemeButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
closeButton.normalImageName = @"button_icon_close.png";
[closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *closeItem = [[UIBarButtonItem alloc] initWithCustomView:closeButton];
[self.navigationItem setLeftBarButtonItem:closeItem];
//2.发送按钮
ThemeButton *sendButton = [[ThemeButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
sendButton.normalImageName = @"button_icon_ok.png";
[sendButton addTarget:self action:@selector(sendAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *sendItem = [[UIBarButtonItem alloc] initWithCustomView:sendButton];
[self.navigationItem setRightBarButtonItem:sendItem];
}
- (void)_createEditorViews{
//1 文本输入视图
_textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 120)];
_textView.font = [UIFont systemFontOfSize:16.0f];
_textView.backgroundColor = [UIColor clearColor];
_textView.editable = YES;
_textView.backgroundColor = [UIColor lightGrayColor];
_textView.layer.cornerRadius = 10;
_textView.layer.borderWidth = 2;
_textView.layer.borderColor = [UIColor blackColor].CGColor;
[self.view addSubview:_textView];
//2 编辑工具栏
_editorBar = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, 55)];
_editorBar.backgroundColor = [UIColor clearColor];
[self.view addSubview:_editorBar];
//3.创建多个编辑按钮
NSArray *imgs = @[
@"compose_toolbar_1.png",
@"compose_toolbar_4.png",
@"compose_toolbar_3.png",
@"compose_toolbar_5.png",
@"compose_toolbar_6.png"
];
for (int i=0; i<imgs.count; i++) {
NSString *imgName = imgs[i];
ThemeButton *button = [[ThemeButton alloc] initWithFrame:CGRectMake(15+(kScreenWidth/5)*i, 20, 40, 33)];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
button.tag = 10+i;
button.normalImageName = imgName;
[_editorBar addSubview:button];
}
}
- (void)buttonAction:(UIButton*)button{
NSLog(@"%li",button.tag);
if (button.tag == 10) {
//选择照片
[self _selectPhoto];
}
}
//发送微博
//- (void)sendAction{
// NSString *text = _textView.text;
// NSString *error = nil;
// if (text.length == 0) {
// error = @"微博内容为空";
// }
// else if(text.length > 140) {
// error = @"微博内容大于140字符";
// }
// if (error != nil) {
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:error delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
// [alertView show];
// return;
// }
//
// NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
// [params setObject:text forKey:@"status"];
//
// //发送
// [DataService sendWeibo:text image:_sendImage block:^(id result) {
// NSLog(@"发送反馈 %@",result);
//
// }];
//
//
//
//
//}
//关闭窗口
- (void)closeAction{
//通过UIWindow找到 MMDRawer
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if ([window.rootViewController isKindOfClass:[MMDrawerController class]]) {
MMDrawerController *mmDrawer = (MMDrawerController *)window.rootViewController;
[mmDrawer closeDrawerAnimated:YES completion:NULL];
}
[_textView resignFirstResponder];
[self dismissViewControllerAnimated:YES completion:NULL];
}
#pragma mark - 键盘弹出通知
- (void)keyBoardWillShow:(NSNotification *)notification{
NSLog(@"%@",notification);
//1 取出键盘frame
NSValue *bounsValue = [notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect frame = [bounsValue CGRectValue];
//2 键盘高度
CGFloat height = frame.size.height;
//3 调整视图的高度
_editorBar.bottom = kScreenHeight - height-60;
}
#pragma mark - 选择照片
- (void)_selectPhoto{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拍照" otherButtonTitles:@"相册", nil];
[actionSheet showInView:self.view];
//UIImagePickerController
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
UIImagePickerControllerSourceType sourceType;
//选择相机 或者 相册
if (buttonIndex == 0) {//拍照
sourceType = UIImagePickerControllerSourceTypeCamera;
BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
if (!isCamera) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"摄像头无法使用" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
[alert show];
return;
}
}else if(buttonIndex == 1){ //选择相册
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}else{
return;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
//照片选择代理
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//弹出相册控制器
[picker dismissViewControllerAnimated:YES completion:nil];
//2 取出照片
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//3 显示缩略图
if (_zoomImageView == nil) {
_zoomImageView = [[ZoomImageView alloc] initWithImage:image];
_zoomImageView.frame = CGRectMake(10, _textView.bottom+10, 80, 80);
[self.view addSubview:_zoomImageView];
_zoomImageView.delegate =self;
}
_zoomImageView.image = image;
_sendImage = image;
}
- (void)imageWillZoomOut:(ZoomImageView *)imageView{
[_textView becomeFirstResponder];
}
-(void)imageWillZoomIn:(ZoomImageView *)imageView{
[_textView resignFirstResponder];
}
@end