// // ServerSettingViewController.m // IBOSS // // Created by guan hong hou on 2017/5/5. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved. // // 功能描述:设置ip端口控制器 // #import "ServerSettingViewController.h" @interface ServerSettingViewController () @end @implementation ServerSettingViewController @synthesize isKeyboardShow; /** viewDidLoad */ - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; _txtServerIp.text = kkServerUrl; _txtServerPort.text = kkServerPort; } /** viewWillDisappear @param animated <#animated description#> */ - (void)viewWillDisappear:(BOOL)animated { //[self.navigationController.navigationBar setHidden:NO]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } /** viewDidAppear @param animated <#animated description#> */ - (void)viewDidAppear:(BOOL)animated { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil]; } /** 触摸屏幕 @param touches <#touches description#> @param event <#event description#> */ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } /** 显示键盘 */ - (void)keyboardWillShow { if(!isKeyboardShow) { [UIView animateWithDuration:0.3f animations:^ { 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); }];} isKeyboardShow = YES; } /** 异常键盘 */ - (void)keyboardWillHide { if(isKeyboardShow) { [UIView animateWithDuration:0.3f animations:^ { 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); }];} isKeyboardShow = NO; } /** 初始化按钮 */ - (void)initUI{ UIView *contentView = [[UIView alloc]init]; [contentView setBackgroundColor:[UIColor whiteColor]]; [self.view addSubview:contentView]; UIImage *pic = [UIImage imageNamed:@"icon_logo"]; UIImageView *bannerView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.width*pic.size.height/pic.size.width)]; [bannerView setImage:pic]; [contentView addSubview:bannerView]; contentView.frame=CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height); pic = [UIImage imageNamed:@"loginbg"]; float inputHeight = (self.view.frame.size.width-46)*pic.size.height/pic.size.width; UIImageView *loginBgImg = [[UIImageView alloc] initWithFrame:CGRectMake(23,self.view.frame.size.height/4,self.view.frame.size.width-46,inputHeight)]; [loginBgImg setImage:[UIImage imageNamed:@"loginbg"]]; [contentView addSubview:loginBgImg]; float lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3; UILabel *titleLbl = [[UILabel alloc]init]; titleLbl.frame=CGRectMake(contentView.frame.size.width/2-100,lbly,200, 20); titleLbl.text = @"服务器地址和端口设置"; titleLbl.textAlignment = NSTextAlignmentCenter; [contentView addSubview:titleLbl]; lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3 + inputHeight / 3; UIImageView *ipImg = [[UIImageView alloc] initWithFrame:CGRectMake(65,lbly,20,15)]; [ipImg setImage:[UIImage imageNamed:@"icon_ip"]]; [contentView addSubview:ipImg]; _txtServerIp = [[UITextField alloc]init]; _txtServerIp.frame=CGRectMake(CGRectGetMaxX(ipImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(ipImg.frame) + 10), 20); _txtServerIp.font = [UIFont systemFontOfSize:TextFontOfSize]; _txtServerIp.textAlignment = NSTextAlignmentCenter; [contentView addSubview: _txtServerIp]; _txtServerIp.placeholder = @"服务器地址"; UIView *ipSeparatorView = [[UIView alloc]init]; [ipSeparatorView setBackgroundColor:[UIColor colorWithRed:213.0/255.0 green:213.0/255.0 blue:213.0/255.0 alpha:1]]; ipSeparatorView.frame=CGRectMake(50, CGRectGetMinY(loginBgImg.frame) + inputHeight * 2/ 3-1, loginBgImg.frame.size.width-60, 1); [contentView addSubview:ipSeparatorView]; lbly = CGRectGetMinY(loginBgImg.frame) + inputHeight / 3 / 3 + inputHeight *2 / 3; UIImageView *portImg = [[UIImageView alloc] initWithFrame:CGRectMake(67,lbly,14,18)]; [portImg setImage:[UIImage imageNamed:@"icon_port"]]; [contentView addSubview:portImg]; _txtServerPort = [[UITextField alloc]init]; _txtServerPort.font = [UIFont systemFontOfSize:TextFontOfSize]; _txtServerPort.textAlignment = NSTextAlignmentCenter; _txtServerPort.placeholder = @"服务器端口"; _txtServerPort.frame=CGRectMake(CGRectGetMaxX(portImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(portImg.frame) + 10), 20); [contentView addSubview: _txtServerPort]; pic = [UIImage imageNamed:@"bt_save"]; _btnSave = [UIButton buttonWithType:UIButtonTypeCustom]; [_btnSave setBackgroundImage:pic forState:UIControlStateNormal]; _btnSave.frame=CGRectMake(self.view.frame.size.width/2-100,CGRectGetMaxY(loginBgImg.frame)+18,200,200*pic.size.height/pic.size.width); [_btnSave addTarget:self action:@selector(saveData) forControlEvents:UIControlEventTouchUpInside]; [contentView addSubview:_btnSave]; pic = [UIImage imageNamed:@"bt_back"]; _btnCancel = [UIButton buttonWithType:UIButtonTypeCustom]; [_btnCancel setBackgroundImage:pic forState:UIControlStateNormal]; _btnCancel.frame=CGRectMake(self.view.frame.size.width/2-100,CGRectGetMaxY(_btnSave.frame)+18,200,200*pic.size.height/pic.size.width); [_btnCancel addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; [contentView addSubview: _btnCancel]; } /** 设定ip和端口 */ - (void)saveData{ kkServerUrl = [_txtServerIp.text stringByReplacingOccurrencesOfString:@" " withString:@""]; kkServerPort = [_txtServerPort.text stringByReplacingOccurrencesOfString:@" " withString:@""]; [self dismissViewControllerAnimated:YES completion:nil]; } /** 返回按钮 */ - (void)goBack{ [self dismissViewControllerAnimated:YES completion:nil]; } @end