PSUpdateUserVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. //
  2. // PSUpdateUserVC.m
  3. // shiku_im
  4. //
  5. // Created by flyeagleTang on 14-6-10.
  6. // Copyright (c) 2014年 Reese. All rights reserved.
  7. //
  8. #import "PSUpdateUserVC.h"
  9. //#import "selectTreeVC.h"
  10. #import "selectValueVC.h"
  11. #import "selectProvinceVC.h"
  12. #import "ImageResize.h"
  13. #import "JXQRCodeViewController.h"
  14. #import "JXActionSheetVC.h"
  15. #import "JXCameraVC.h"
  16. #import "JXSetShikuNumVC.h"
  17. #import "JXInputValueVC.h"
  18. #define HEIGHT 56
  19. #define IMGSIZE 36
  20. @interface PSUpdateUserVC ()<UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, JXActionSheetVCDelegate,JXCameraVCDelegate,JXSetShikuNumVCDelegate,UIScrollViewDelegate>
  21. @property (nonatomic, assign) BOOL isUpdate;
  22. @property (nonatomic, strong) UILabel *desLabel;
  23. @end
  24. @implementation PSUpdateUserVC
  25. @synthesize user;
  26. - (id)init
  27. {
  28. self = [super init];
  29. if (self) {
  30. self.isGotoBack = YES;
  31. if(self.isRegister)
  32. self.title = [NSString stringWithFormat:@"4.%@",Localized(@"PSUpdateUserVC")];
  33. else
  34. self.title = Localized(@"JX_BaseInfo");
  35. self.heightFooter = 0;
  36. self.heightHeader = JX_SCREEN_TOP;
  37. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  38. [self createHeadAndFoot];
  39. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  40. self.tableBody.scrollEnabled = YES;
  41. self.tableBody.delegate = self;
  42. // UIButton * qrButton = [UIButton buttonWithType:UIButtonTypeCustom];
  43. // qrButton.frame = CGRectMake(JX_SCREEN_WIDTH-35-8, 30, 35, 30);
  44. // [qrButton setBackgroundImage:[UIImage imageNamed:@"qrcodeImage_white"] forState:UIControlStateNormal];
  45. // [qrButton setBackgroundImage:[UIImage imageNamed:@"qrcodeImage_white"] forState:UIControlStateHighlighted];
  46. // [qrButton addTarget:self action:@selector(showUserQRCode) forControlEvents:UIControlEventTouchUpInside];
  47. // [self.tableHeader addSubview:qrButton];
  48. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  49. [g_notify postNotificationName:kUpdateUserNotifaction object:self userInfo:nil];
  50. });
  51. [g_server delHeadImage:user.userId];
  52. [self createCustomView];
  53. [g_notify addObserver:self selector:@selector(changeKeyBoard:) name:UIKeyboardWillShowNotification object:nil];
  54. [g_notify addObserver:self selector:@selector(updateUserInfo:) name:kXMPPMessageUpadteUserInfoNotification object:nil];
  55. }
  56. return self;
  57. }
  58. - (void)updateUserInfo:(NSNotification *)noti {
  59. [g_server getUser:g_server.myself.userId toView:self];
  60. }
  61. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  62. _date.hidden = YES;
  63. }
  64. - (void) createCustomView {
  65. int h = 0;
  66. NSString* s;
  67. JXImageView* iv;
  68. iv = [[JXImageView alloc]init];
  69. iv.frame = self.tableBody.bounds;
  70. iv.delegate = self;
  71. iv.didTouch = @selector(hideKeyboard);
  72. [self.tableBody addSubview:iv];
  73. iv = [self createButton:@"头像" drawTop:NO drawBottom:YES must:YES click:@selector(pickImage)];
  74. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  75. _head = [[JXImageView alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-IMGSIZE-41, (HEIGHT-IMGSIZE)/2, IMGSIZE, IMGSIZE)];
  76. _head.layer.cornerRadius = IMGSIZE/2;
  77. _head.layer.masksToBounds = YES;
  78. _head.image = self.headImage;
  79. s = user.userId;
  80. [g_server getHeadImageLarge:s userName:user.userNickname imageView:_head];
  81. [iv addSubview:_head];
  82. h+=iv.frame.size.height;
  83. NSString* city = [g_constant getAddressForNumber:user.provinceId cityId:user.cityId areaId:user.areaId];
  84. iv = [self createButton:Localized(@"JX_Name") drawTop:NO drawBottom:YES must:YES click:nil];
  85. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  86. _name = [self createTextField:iv default:user.userNickname hint:Localized(@"JX_InputName")];
  87. // _name.userInteractionEnabled = self.isRegister;
  88. h+=iv.frame.size.height;
  89. [_name addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
  90. iv = [self createButton:Localized(@"JX_Sex") drawTop:NO drawBottom:YES must:YES click:nil];
  91. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  92. _sex = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:Localized(@"JX_Wuman"),Localized(@"JX_Man"),nil]];
  93. _sex.frame = CGRectMake(JX_SCREEN_WIDTH -100 - 15,INSETS+3,100,HEIGHT-INSETS*2-6);
  94. _sex.userInteractionEnabled = YES;
  95. //样式
  96. // _sex.segmentedControlStyle= UISegmentedControlStyleBar;
  97. _sex.tintColor = THEMECOLOR;
  98. _sex.layer.cornerRadius = 5;
  99. _sex.layer.borderWidth = 1.5;
  100. _sex.layer.borderColor = [THEMECOLOR CGColor];
  101. _sex.clipsToBounds = YES;
  102. //设置文字属性
  103. _sex.selectedSegmentIndex = [user.sex boolValue];
  104. _sex.apportionsSegmentWidthsByContent = NO;
  105. [iv addSubview:_sex];
  106. // [_sex release];
  107. h+=iv.frame.size.height;
  108. iv = [self createButton:Localized(@"JX_BirthDay") drawTop:NO drawBottom:YES must:YES click:nil];
  109. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  110. _birthday = [self createTextField:iv default:[TimeUtil getDateStr:[user.birthday timeIntervalSince1970]] hint:Localized(@"JX_BirthDay")];
  111. h+=iv.frame.size.height;
  112. if ([g_config.isOpenPositionService intValue] == 0) {
  113. iv = [self createButton:Localized(@"JXUserInfoVC_Address") drawTop:NO drawBottom:YES must:YES click:@selector(onCity)];
  114. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  115. _city = [self createLabel:iv default:city];
  116. h+=iv.frame.size.height;
  117. }
  118. if (!self.isRegister) {
  119. iv = [self createButton:Localized(@"JX_MyQRImage") drawTop:NO drawBottom:YES must:NO click:@selector(showUserQRCode)];
  120. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  121. h+=iv.frame.size.height;
  122. // UIImageView * qrView = [[UIImageView alloc] init];
  123. // qrView.frame = CGRectMake(JX_SCREEN_WIDTH-INSETS-20-3-30, 10, 30, 30);
  124. // qrView.image = [UIImage imageNamed:@"qrcodeImage"];
  125. // [iv addSubview:qrView];
  126. iv = [self createButton:Localized(@"JX_MyPhoneNumber") drawTop:NO drawBottom:YES must:NO click:nil];
  127. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  128. [self createLabel:iv default:g_myself.telephone];
  129. h+=iv.frame.size.height;
  130. // 即时通讯号
  131. if ([self.user.setAccountCount integerValue] > 0) {
  132. iv = [self createButton:Localized(@"JX_Communication") drawTop:NO drawBottom:NO must:NO click:nil];
  133. }else {
  134. iv = [self createButton:Localized(@"JX_Communication") drawTop:NO drawBottom:NO must:NO click:@selector(onShikuNum)];
  135. }
  136. UILabel *lab = [self createLabel:iv default:self.user.account];
  137. if ([self.user.setAccountCount integerValue] <= 0) {
  138. CGSize lSize = [self.user.account sizeWithAttributes:@{NSFontAttributeName:SYSFONT(15)}];
  139. CGRect frame = lab.frame;
  140. frame.origin.x = JX_SCREEN_WIDTH - lSize.width - INSETS - 20;
  141. lab.frame = frame;
  142. }
  143. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  144. // [self createLabel:iv default:g_myself.telephone];
  145. h+=iv.frame.size.height;
  146. if ([g_config.registerInviteCode intValue] == 2) {
  147. iv = [self createButton:Localized(@"JX_InvitationCode") drawTop:YES drawBottom:NO must:NO click:nil];
  148. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  149. [self createLabel:iv default:g_myself.myInviteCode];
  150. h+=iv.frame.size.height;
  151. }
  152. iv = [self createButton:@"个性签名" drawTop:YES drawBottom:NO must:NO click:@selector(onIputDes)];
  153. iv.frame = CGRectMake(0, h, JX_SCREEN_WIDTH, HEIGHT);
  154. _desLabel = [self createLabel:iv default:self.user.userDescription];
  155. h+=iv.frame.size.height;
  156. if (self.user.userDescription.length > 0) {
  157. [self updateDesLabelFrame];
  158. }
  159. }
  160. h+=40;
  161. UIButton* _btn;
  162. if(self.isRegister)
  163. _btn = [UIFactory createCommonButton:Localized(@"JX_NextStep") target:self action:@selector(onInsert)];
  164. else
  165. _btn = [UIFactory createCommonButton:Localized(@"JX_Update") target:self action:@selector(onUpdate)];
  166. _btn.layer.cornerRadius = 7;
  167. _btn.clipsToBounds = YES;
  168. _btn.custom_acceptEventInterval = 1.0f;
  169. _btn.frame = CGRectMake(INSETS, h, WIDTH, 40);
  170. [self.tableBody addSubview:_btn];
  171. int height = 200;
  172. if (THE_DEVICE_HAVE_HEAD) {
  173. height = 235;
  174. }
  175. _date = [[JXDatePicker alloc] initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT-height, JX_SCREEN_WIDTH, height)];
  176. _date.datePicker.datePickerMode = UIDatePickerModeDate;
  177. _date.date = user.birthday;
  178. _date.delegate = self;
  179. _date.didChange = @selector(onDate:);
  180. _date.didSelect = @selector(onDate:);
  181. if (self.tableBody.frame.size.height < h+HEIGHT+INSETS) {
  182. self.tableBody.contentSize = CGSizeMake(0, h+HEIGHT+INSETS);
  183. }
  184. }
  185. - (void)updateDesLabelFrame {
  186. CGSize lSize = [self.user.userDescription sizeWithAttributes:@{NSFontAttributeName:SYSFONT(15)}];
  187. if (lSize.width > JX_SCREEN_WIDTH/2-INSETS - 20) {
  188. lSize.width = JX_SCREEN_WIDTH/2-INSETS - 20;
  189. }
  190. CGRect frame = _desLabel.frame;
  191. frame.origin.x = JX_SCREEN_WIDTH - lSize.width - INSETS - 20;
  192. frame.size.width = lSize.width;
  193. _desLabel.frame = frame;
  194. }
  195. - (void)onIputDes {
  196. JXInputValueVC* vc = [JXInputValueVC alloc];
  197. vc.value = g_myself.userDescription;
  198. vc.title = @"个性签名";
  199. vc.delegate = self;
  200. vc.didSelect = @selector(onSaveRoomName:);
  201. vc.isLimit = YES;
  202. vc.limitLen = 30;
  203. vc = [vc init];
  204. [g_navigation pushViewController:vc animated:YES];
  205. }
  206. - (void)onSaveRoomName:(JXInputValueVC*)vc {
  207. self.isUpdate = YES;
  208. _desLabel.text = vc.value;
  209. user.userDescription = vc.value;
  210. [self updateDesLabelFrame];
  211. }
  212. -(void)dealloc{
  213. // NSLog(@"PSUpdateUserVC.dealloc");
  214. [g_notify removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  215. [g_notify removeObserver:self name:kXMPPMessageUpadteUserInfoNotification object:nil];
  216. // [_image release];
  217. self.user = nil;
  218. [_date removeFromSuperview];
  219. // [_date release];
  220. // [super dealloc];
  221. }
  222. - (void)viewWillAppear:(BOOL)animated{
  223. [super viewWillAppear:animated];
  224. }
  225. - (void)viewDidLoad
  226. {
  227. [super viewDidLoad];
  228. // Do any additional setup after loading the view.
  229. }
  230. - (void)didReceiveMemoryWarning
  231. {
  232. [super didReceiveMemoryWarning];
  233. // Dispose of any resources that can be recreated.
  234. }
  235. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
  236. if(textField == _birthday){
  237. [self.view endEditing:YES];
  238. [g_window addSubview:_date];
  239. _date.hidden = NO;
  240. return NO;
  241. }else{
  242. if (textField == _name && textField.text.length > 0) {
  243. _name.frame = CGRectMake(JX_SCREEN_WIDTH/2-8,INSETS,JX_SCREEN_WIDTH/2,HEIGHT-INSETS*2);
  244. }
  245. _date.hidden = YES;
  246. return YES;
  247. }
  248. }
  249. - (void)textDidChange:(UITextField *)textField {
  250. if (textField == _name) {
  251. if (textField.text.length > 0) {
  252. _name.frame = CGRectMake(JX_SCREEN_WIDTH/2-8,INSETS,JX_SCREEN_WIDTH/2,HEIGHT-INSETS*2);
  253. }else {
  254. _name.frame = CGRectMake(JX_SCREEN_WIDTH/2-15,INSETS,JX_SCREEN_WIDTH/2,HEIGHT-INSETS*2);
  255. }
  256. [self validationText:textField];
  257. }
  258. }
  259. //过滤非法字符
  260. - (NSString *)disable_Text:(NSString *)text
  261. {
  262. NSLog(@"过滤--->%@",text);
  263. text = [text stringByReplacingOccurrencesOfString:@" " withString:@""];
  264. text = [text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  265. //过滤emoji表情
  266. return [self disable_emoji:text];
  267. }
  268. //过滤emoj表情
  269. - (NSString *)disable_emoji:(NSString *)text
  270. {
  271. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]" options:NSRegularExpressionCaseInsensitive error:nil];
  272. NSString *modifiedString = [regex stringByReplacingMatchesInString:text
  273. options:0
  274. range:NSMakeRange(0, [text length])
  275. withTemplate:@""];
  276. return modifiedString;
  277. }
  278. - (NSString *)validationText:(UITextField *)textField
  279. {
  280. //不论中文英文,如果有空格,回车,都要过滤掉
  281. NSString *toBeString = [self disable_Text:textField.text];
  282. NSString *lang = [textField.textInputMode primaryLanguage];
  283. NSLog(@"%@",lang);
  284. //判断输入法
  285. if ([lang isEqualToString:@"zh-Hans"]) {
  286. UITextRange *selectedRange = [textField markedTextRange];
  287. UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
  288. if (!position) {
  289. if (toBeString.length>=8) {
  290. NSString *strNew = [NSString stringWithString:toBeString];
  291. [textField setText:[strNew substringToIndex:8]];
  292. }else{
  293. [textField setText:toBeString];
  294. }
  295. }
  296. else
  297. {
  298. NSLog(@"输入的英文还没有转化为汉字的状态");
  299. }
  300. }
  301. else{
  302. if (toBeString.length > 8) {
  303. textField.text = [toBeString substringToIndex:8];
  304. }else{
  305. textField.text = toBeString;
  306. }
  307. }
  308. return textField.text;
  309. }
  310. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  311. if (textField == _name) {
  312. _name.frame = CGRectMake(JX_SCREEN_WIDTH/2-15,INSETS,JX_SCREEN_WIDTH/2,HEIGHT-INSETS*2);
  313. }
  314. return YES;
  315. }
  316. - (IBAction)onDate:(id)sender {
  317. NSDate *selected = [_date date];
  318. // user.birthday = selected;
  319. _birthday.text = [TimeUtil formatDate:selected format:@"yyyy-MM-dd"];
  320. // _date.hidden = YES;
  321. }
  322. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  323. [_wait stop];
  324. if( [aDownload.action isEqualToString:act_UploadHeadImage] ){
  325. // _head.image = _image;
  326. // [_image release];
  327. _image = nil;
  328. [g_server delHeadImage:user.userId];
  329. if(self.isRegister){
  330. [g_App showMainUI];
  331. [g_App showAlert:Localized(@"JX_RegOK")];
  332. }else{
  333. [g_App showAlert:Localized(@"JXAlert_UpdateOK")];
  334. }
  335. [g_notify postNotificationName:kUpdateUserNotifaction object:self userInfo:nil];
  336. [self actionQuit];
  337. }
  338. if( [aDownload.action isEqualToString:act_Register] || [aDownload.action isEqualToString:act_RegisterV1] ){
  339. [g_server doLoginOK:dict user:user];
  340. self.user = g_server.myself;
  341. [g_server uploadHeadImage:user.userId image:_image toView:self];
  342. [g_notify postNotificationName:kRegisterNotifaction object:self userInfo:nil];
  343. }
  344. if( [aDownload.action isEqualToString:act_UserUpdate] ){
  345. if(_image)
  346. [g_server uploadHeadImage:user.userId image:_image toView:self];
  347. else{
  348. user.userNickname = _name.text;
  349. user.sex = [NSNumber numberWithInteger:_sex.selectedSegmentIndex];
  350. user.birthday = _date.date;
  351. user.cityId = [NSNumber numberWithInt:[_city.text intValue]];
  352. [g_App showAlert:Localized(@"JXAlert_UpdateOK")];
  353. g_server.myself.userNickname = user.userNickname;
  354. g_server.myself.userDescription = user.userDescription;
  355. [g_default setObject:g_server.myself.userNickname forKey:kMY_USER_NICKNAME];
  356. [g_notify postNotificationName:kUpdateUserNotifaction object:self userInfo:nil];
  357. [self actionQuit];
  358. }
  359. }
  360. if ([aDownload.action isEqualToString:act_UserGet]) {
  361. JXUserObject* user = [[JXUserObject alloc]init];
  362. [user getDataFromDict:dict];
  363. self.user = user;
  364. [self createCustomView];
  365. }
  366. }
  367. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  368. [_wait stop];
  369. return show_error;
  370. }
  371. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  372. [_wait stop];
  373. return show_error;
  374. }
  375. -(void) didServerConnectStart:(JXConnection*)aDownload{
  376. [_wait start];
  377. }
  378. -(JXImageView*)createButton:(NSString*)title drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom must:(BOOL)must click:(SEL)click{
  379. JXImageView* btn = [[JXImageView alloc] init];
  380. btn.backgroundColor = [UIColor whiteColor];
  381. btn.userInteractionEnabled = YES;
  382. if(click)
  383. btn.didTouch = click;
  384. else
  385. btn.didTouch = @selector(hideKeyboard);
  386. btn.delegate = self;
  387. [self.tableBody addSubview:btn];
  388. // [btn release];
  389. // if(must){
  390. // UILabel* p = [[UILabel alloc] initWithFrame:CGRectMake(INSETS, 5, 20, HEIGHT-5)];
  391. // p.text = @"*";
  392. // p.font = g_factory.font18;
  393. // p.backgroundColor = [UIColor clearColor];
  394. // p.textColor = [UIColor redColor];
  395. // p.textAlignment = NSTextAlignmentCenter;
  396. // [btn addSubview:p];
  397. // }
  398. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(15, 0, 130, HEIGHT)];
  399. p.text = title;
  400. p.font = g_factory.font15;
  401. p.backgroundColor = [UIColor clearColor];
  402. p.textColor = [UIColor blackColor];
  403. [btn addSubview:p];
  404. if(drawTop){
  405. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,0,JX_SCREEN_WIDTH-15,LINE_WH)];
  406. line.backgroundColor = THE_LINE_COLOR;
  407. [btn addSubview:line];
  408. }
  409. if(drawBottom){
  410. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(15, HEIGHT-LINE_WH,JX_SCREEN_WIDTH-15,LINE_WH)];
  411. line.backgroundColor = THE_LINE_COLOR;
  412. [btn addSubview:line];
  413. }
  414. if(click){
  415. UIImageView* iv;
  416. iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, (HEIGHT-13)/2, 7, 13)];
  417. iv.image = [UIImage imageNamed:@"new_icon_>"];
  418. [btn addSubview:iv];
  419. }
  420. return btn;
  421. }
  422. -(UITextField*)createTextField:(UIView*)parent default:(NSString*)s hint:(NSString*)hint{
  423. UITextField* p = [[UITextField alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2-15,INSETS,JX_SCREEN_WIDTH/2,HEIGHT-INSETS*2)];
  424. p.delegate = self;
  425. p.autocorrectionType = UITextAutocorrectionTypeNo;
  426. p.autocapitalizationType = UITextAutocapitalizationTypeNone;
  427. p.enablesReturnKeyAutomatically = YES;
  428. p.borderStyle = UITextBorderStyleNone;
  429. p.returnKeyType = UIReturnKeyDone;
  430. p.clearButtonMode = UITextFieldViewModeWhileEditing;
  431. p.textAlignment = NSTextAlignmentRight;
  432. p.userInteractionEnabled = YES;
  433. p.textColor = HEXCOLOR(0x999999);
  434. p.text = s;
  435. p.placeholder = hint;
  436. p.font = g_factory.font15;
  437. [parent addSubview:p];
  438. return p;
  439. }
  440. -(UILabel*)createLabel:(UIView*)parent default:(NSString*)s{
  441. UILabel* p = [[UILabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2,INSETS,JX_SCREEN_WIDTH/2 -30,HEIGHT-INSETS*2)];
  442. p.userInteractionEnabled = NO;
  443. p.text = s;
  444. p.font = g_factory.font15;
  445. p.textAlignment = NSTextAlignmentRight;
  446. p.textColor = HEXCOLOR(0x999999);
  447. [parent addSubview:p];
  448. CGSize size = [s boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font15} context:nil].size;
  449. CGRect frame = p.frame;
  450. frame.size.width = size.width;
  451. frame.origin.x = JX_SCREEN_WIDTH - size.width - INSETS;
  452. p.frame = frame;
  453. NSString* city = [g_constant getAddressForNumber:user.provinceId cityId:user.cityId areaId:user.areaId];
  454. if ([s isEqualToString:city]) {
  455. CGSize size = [Localized(@"JXUserInfoVC_Address") boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:g_factory.font13} context:nil].size;
  456. p.frame = CGRectMake(size.width + 30 + 10, INSETS, JX_SCREEN_WIDTH - size.width - 30 - 10 - 30, HEIGHT - INSETS * 2);
  457. }
  458. if ([s isEqualToString:g_myself.myInviteCode]) {
  459. p.userInteractionEnabled = YES;
  460. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPre:)];
  461. [p addGestureRecognizer:longPress];
  462. _inviteCode = p;
  463. }
  464. return p;
  465. }
  466. // 使label能够成为响应事件,为了能接收到事件(能成为第一响应者)
  467. - (BOOL)canBecomeFirstResponder{
  468. return YES;
  469. }
  470. // 可以控制响应的方法
  471. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{
  472. return (action == @selector(copy:));
  473. }
  474. //针对响应方法的实现,最主要的复制的两句代码
  475. - (void)copy:(id)sender{
  476. //UIPasteboard:该类支持写入和读取数据,类似剪贴板
  477. UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
  478. pasteBoard.string = [_inviteCode text];
  479. }
  480. // 处理长按事件
  481. - (void)longPre:(UILongPressGestureRecognizer *)recognizer{
  482. [self becomeFirstResponder]; // 用于UIMenuController显示,缺一不可
  483. UIView *view = recognizer.view;
  484. //UIMenuController:可以通过这个类实现点击内容,或者长按内容时展示出复制等选择的项,每个选项都是一个UIMenuItem对象
  485. // UIMenuItem *copyLink = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copy:)];
  486. // [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:copyLink, nil]];
  487. [[UIMenuController sharedMenuController] setTargetRect:view.frame inView:view.superview];
  488. [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
  489. }
  490. -(void)onCity{
  491. if([self hideKeyboard])
  492. return;
  493. selectProvinceVC* vc = [selectProvinceVC alloc];
  494. vc.delegate = self;
  495. vc.didSelect = @selector(onSelCity:);
  496. vc.showCity = YES;
  497. vc.showArea = NO;
  498. vc.parentId = 1;
  499. vc = [vc init];
  500. // [g_window addSubview:vc.view];
  501. [g_navigation pushViewController:vc animated:YES];
  502. }
  503. -(void)onSelCity:(selectProvinceVC*)sender{
  504. if (self) {
  505. [self resetViewFrame];
  506. }
  507. if ([user.cityId intValue] != sender.cityId) {
  508. self.isUpdate = YES;
  509. }
  510. user.cityId = [NSNumber numberWithInt:sender.cityId];
  511. user.provinceId = [NSNumber numberWithInt:sender.provinceId];
  512. user.areaId = [NSNumber numberWithInt:sender.areaId];
  513. user.countryId = [NSNumber numberWithInt:1];
  514. _city.text = sender.selValue;
  515. }
  516. //归位
  517. - (void)resetViewFrame{
  518. [UIView animateWithDuration:0.3 animations:^{
  519. self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, self.view.frame.size.height);
  520. }];
  521. }
  522. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  523. {
  524. _image = [ImageResize image:[info objectForKey:@"UIImagePickerControllerEditedImage"] fillSize:CGSizeMake(640, 640)];
  525. // [_image retain];
  526. _head.image = _image;
  527. [picker dismissViewControllerAnimated:YES completion:nil];
  528. // [picker.view removeFromSuperview];
  529. // [self dismissModalViewControllerAnimated:YES];
  530. // [picker release];
  531. }
  532. - (void) pickImage
  533. {
  534. [self hideKeyboard];
  535. JXActionSheetVC *actionVC = [[JXActionSheetVC alloc] initWithImages:@[] names:@[Localized(@"JX_ChoosePhoto"),Localized(@"JX_TakePhoto")]];
  536. actionVC.delegate = self;
  537. [self presentViewController:actionVC animated:NO completion:nil];
  538. }
  539. - (void)actionSheet:(JXActionSheetVC *)actionSheet didButtonWithIndex:(NSInteger)index {
  540. if (index == 0) {
  541. UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
  542. ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  543. ipc.delegate = self;
  544. ipc.allowsEditing = YES;
  545. //选择图片模式
  546. ipc.modalPresentationStyle = UIModalPresentationCurrentContext;
  547. // [g_window addSubview:ipc.view];
  548. if (IS_PAD) {
  549. UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:ipc];
  550. [pop presentPopoverFromRect:CGRectMake((self.view.frame.size.width - 320) / 2, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  551. }else {
  552. [self presentViewController:ipc animated:YES completion:nil];
  553. }
  554. }else {
  555. JXCameraVC *vc = [JXCameraVC alloc];
  556. vc.cameraDelegate = self;
  557. vc.isPhoto = YES;
  558. vc = [vc init];
  559. [self presentViewController:vc animated:YES completion:nil];
  560. }
  561. }
  562. - (void)cameraVC:(JXCameraVC *)vc didFinishWithImage:(UIImage *)image {
  563. _image = [ImageResize image:image fillSize:CGSizeMake(640, 640)];
  564. // [_image retain];
  565. _head.image = _image;
  566. }
  567. -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  568. {
  569. [picker dismissViewControllerAnimated:YES completion:nil];
  570. // [picker.view removeFromSuperview];
  571. // [picker release];
  572. // [self dismissModalViewControllerAnimated:YES];
  573. }
  574. -(void)onUpdate{
  575. if(![self getInputValue])
  576. return;
  577. if (_image || self.isUpdate) {
  578. [g_server updateUser:user toView:self];
  579. }else {
  580. [self actionQuit];
  581. }
  582. }
  583. -(void)onInsert{
  584. if(![self getInputValue])
  585. return;
  586. // [g_server registerUser:user inviteCode:nil workexp:0 diploma:0 isSmsRegister:NO toView:self];
  587. [g_loginServer registerUserV1:user type:0 inviteCode:nil workexp:0 diploma:0 isSmsRegister:NO smsCode:nil password:@"" memberAccount:@"" toView:self];
  588. }
  589. -(BOOL)getInputValue{
  590. if(_image==nil && self.isRegister){
  591. [g_App showAlert:Localized(@"JX_SetHead")];
  592. return NO;
  593. }
  594. if([_name.text length]<=0){
  595. [g_App showAlert:Localized(@"JX_InputName")];
  596. return NO;
  597. }
  598. if(user.cityId<=0){
  599. [g_App showAlert:Localized(@"JX_Live")];
  600. return NO;
  601. }
  602. if (_birthday.text.length <= 0) {
  603. [g_App showAlert:Localized(@"JX_SelectDateOfBirth")];
  604. return NO;
  605. }
  606. if (![user.userNickname isEqualToString:_name.text] || [user.birthday timeIntervalSince1970] != [_date.date timeIntervalSince1970] || [user.sex integerValue] != _sex.selectedSegmentIndex) {
  607. self.isUpdate = YES;
  608. }
  609. user.userNickname = _name.text;
  610. user.birthday = _date.date;
  611. user.sex = [NSNumber numberWithBool:_sex.selectedSegmentIndex];
  612. return YES;
  613. }
  614. -(BOOL)hideKeyboard{
  615. BOOL b = _name.editing || _pwd.editing || _repeat.editing || _birthday.editing;
  616. _date.hidden = YES;
  617. [self.view endEditing:YES];
  618. // [self.view setFrame:self.view.bounds];
  619. return b;
  620. }
  621. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  622. {
  623. [self.view endEditing:YES];
  624. return YES;
  625. }
  626. -(void)changeKeyBoard:(NSNotification *)aNotifacation
  627. {
  628. // return;
  629. //获取到键盘frame 变化之前的frame
  630. NSValue *keyboardBeginBounds=[[aNotifacation userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey];
  631. CGRect beginRect=[keyboardBeginBounds CGRectValue];
  632. //获取到键盘frame变化之后的frame
  633. NSValue *keyboardEndBounds=[[aNotifacation userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey];
  634. CGRect endRect=[keyboardEndBounds CGRectValue];
  635. CGFloat deltaY=endRect.origin.y-beginRect.origin.y;
  636. //拿frame变化之后的origin.y-变化之前的origin.y,其差值(带正负号)就是我们self.view的y方向上的增量
  637. deltaY=-endRect.size.height;
  638. // NSLog(@"deltaY:%f",deltaY);
  639. //取消界面上移
  640. // [self.view setFrame:CGRectMake(0, JX_SCREEN_HEIGHT+deltaY-self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
  641. }
  642. -(void)showUserQRCode{
  643. JXQRCodeViewController * qrVC = [[JXQRCodeViewController alloc] init];
  644. qrVC.type = QRUserType;
  645. qrVC.userId = user.userId;
  646. qrVC.account = user.account;
  647. qrVC.nickName = user.userNickname;
  648. qrVC.sex = user.sex;
  649. // [g_window addSubview:qrVC.view];
  650. [g_navigation pushViewController:qrVC animated:YES];
  651. }
  652. - (void)onShikuNum {
  653. JXSetShikuNumVC *vc = [[JXSetShikuNumVC alloc] init];
  654. vc.delegate = self;
  655. vc.user = user;
  656. [g_navigation pushViewController:vc animated:YES];
  657. }
  658. - (void)setShikuNum:(JXSetShikuNumVC *)setShikuNumVC updateSuccessWithAccount:(NSString *)account {
  659. [self.tableBody.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  660. [self createCustomView];
  661. }
  662. @end