ServerSettingViewController.m 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // ServerSettingViewController.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2017/5/5.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:设置ip端口控制器
  9. //
  10. #import "ServerSettingViewController.h"
  11. @interface ServerSettingViewController ()
  12. @end
  13. @implementation ServerSettingViewController
  14. @synthesize isKeyboardShow;
  15. /**
  16. viewDidLoad
  17. */
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self initUI];
  21. _txtServerIp.text = kkServerUrl;
  22. _txtServerPort.text = kkServerPort;
  23. }
  24. /**
  25. viewWillDisappear
  26. @param animated <#animated description#>
  27. */
  28. - (void)viewWillDisappear:(BOOL)animated
  29. {
  30. //[self.navigationController.navigationBar setHidden:NO];
  31. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification
  32. object:nil];
  33. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification
  34. object:nil];
  35. }
  36. /**
  37. viewDidAppear
  38. @param animated <#animated description#>
  39. */
  40. - (void)viewDidAppear:(BOOL)animated
  41. {
  42. [[NSNotificationCenter defaultCenter] addObserver:self
  43. selector:@selector(keyboardWillShow)
  44. name:UIKeyboardWillShowNotification
  45. object:nil];
  46. [[NSNotificationCenter defaultCenter] addObserver:self
  47. selector:@selector(keyboardWillHide)
  48. name:UIKeyboardWillHideNotification
  49. object:nil];
  50. }
  51. /**
  52. 触摸屏幕
  53. @param touches <#touches description#>
  54. @param event <#event description#>
  55. */
  56. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  57. {
  58. [self.view endEditing:YES];
  59. }
  60. /**
  61. 显示键盘
  62. */
  63. - (void)keyboardWillShow {
  64. if(!isKeyboardShow) {
  65. [UIView animateWithDuration:0.3f animations:^ {
  66. self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y-160, self.view.frame.size.width, self.view.frame.size.height);
  67. }];}
  68. isKeyboardShow = YES;
  69. }
  70. /**
  71. 异常键盘
  72. */
  73. - (void)keyboardWillHide {
  74. if(isKeyboardShow) {
  75. [UIView animateWithDuration:0.3f animations:^ {
  76. self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+160, self.view.frame.size.width, self.view.frame.size.height);
  77. }];}
  78. isKeyboardShow = NO;
  79. }
  80. /**
  81. 初始化按钮
  82. */
  83. - (void)initUI{
  84. UIView *contentView = [[UIView alloc]init];
  85. [contentView setBackgroundColor:[UIColor whiteColor]];
  86. [self.view addSubview:contentView];
  87. UIImage *pic = [UIImage imageNamed:@"icon_logo"];
  88. UIImageView *bannerView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.width*pic.size.height/pic.size.width)];
  89. [bannerView setImage:pic];
  90. [contentView addSubview:bannerView];
  91. contentView.frame=CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height);
  92. pic = [UIImage imageNamed:@"loginbg"];
  93. float inputHeight = (self.view.frame.size.width-46)*pic.size.height/pic.size.width;
  94. UIImageView *loginBgImg = [[UIImageView alloc] initWithFrame:CGRectMake(23,self.view.frame.size.height/4,self.view.frame.size.width-46,inputHeight)];
  95. [loginBgImg setImage:[UIImage imageNamed:@"loginbg"]];
  96. [contentView addSubview:loginBgImg];
  97. float lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3;
  98. UILabel *titleLbl = [[UILabel alloc]init];
  99. titleLbl.frame=CGRectMake(contentView.frame.size.width/2-100,lbly,200, 20);
  100. titleLbl.text = @"服务器地址和端口设置";
  101. titleLbl.textAlignment = NSTextAlignmentCenter;
  102. [contentView addSubview:titleLbl];
  103. lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3 + inputHeight / 3;
  104. UIImageView *ipImg = [[UIImageView alloc] initWithFrame:CGRectMake(65,lbly,20,15)];
  105. [ipImg setImage:[UIImage imageNamed:@"icon_ip"]];
  106. [contentView addSubview:ipImg];
  107. _txtServerIp = [[UITextField alloc]init];
  108. _txtServerIp.frame=CGRectMake(CGRectGetMaxX(ipImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(ipImg.frame) + 10), 20);
  109. _txtServerIp.font = [UIFont systemFontOfSize:TextFontOfSize];
  110. _txtServerIp.textAlignment = NSTextAlignmentCenter;
  111. [contentView addSubview: _txtServerIp];
  112. _txtServerIp.placeholder = @"服务器地址";
  113. UIView *ipSeparatorView = [[UIView alloc]init];
  114. [ipSeparatorView setBackgroundColor:[UIColor colorWithRed:213.0/255.0 green:213.0/255.0 blue:213.0/255.0 alpha:1]];
  115. ipSeparatorView.frame=CGRectMake(50, CGRectGetMinY(loginBgImg.frame) + inputHeight * 2/ 3-1, loginBgImg.frame.size.width-60, 1);
  116. [contentView addSubview:ipSeparatorView];
  117. lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3 + inputHeight *2 / 3;
  118. UIImageView *portImg = [[UIImageView alloc] initWithFrame:CGRectMake(67,lbly,14,18)];
  119. [portImg setImage:[UIImage imageNamed:@"icon_port"]];
  120. [contentView addSubview:portImg];
  121. _txtServerPort = [[UITextField alloc]init];
  122. _txtServerPort.font = [UIFont systemFontOfSize:TextFontOfSize];
  123. _txtServerPort.textAlignment = NSTextAlignmentCenter;
  124. _txtServerPort.placeholder = @"服务器端口";
  125. _txtServerPort.frame=CGRectMake(CGRectGetMaxX(portImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(portImg.frame) + 10), 20);
  126. [contentView addSubview: _txtServerPort];
  127. pic = [UIImage imageNamed:@"bt_save"];
  128. _btnSave = [UIButton buttonWithType:UIButtonTypeCustom];
  129. [_btnSave setBackgroundImage:pic forState:UIControlStateNormal];
  130. _btnSave.frame=CGRectMake(self.view.frame.size.width/2-100,CGRectGetMaxY(loginBgImg.frame)+18,200,200*pic.size.height/pic.size.width);
  131. [_btnSave addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside];
  132. [contentView addSubview:_btnSave];
  133. pic = [UIImage imageNamed:@"bt_back"];
  134. _btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
  135. [_btnCancel setBackgroundImage:pic forState:UIControlStateNormal];
  136. _btnCancel.frame=CGRectMake(self.view.frame.size.width/2-100,CGRectGetMaxY(_btnSave.frame)+18,200,200*pic.size.height/pic.size.width);
  137. [_btnCancel addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  138. [contentView addSubview: _btnCancel];
  139. }
  140. /**
  141. 设定ip和端口
  142. */
  143. - (void)saveData{
  144. kkServerUrl = [_txtServerIp.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  145. kkServerPort = [_txtServerPort.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  146. [self dismissViewControllerAnimated:YES completion:nil];
  147. }
  148. /**
  149. 返回按钮
  150. */
  151. - (void)goBack{
  152. [self dismissViewControllerAnimated:YES completion:nil];
  153. }
  154. @end