// // ServerSettingViewController.m // IBOSSmini // // Created by guan hong hou on 2017/5/5. // Copyright © 2017年 elongtian. All rights reserved. // #import "ServerSettingViewController.h" @interface ServerSettingViewController () @end @implementation ServerSettingViewController @synthesize keyboardShow; /** viewDidLoad */ - (void)viewDidLoad { [super viewDidLoad]; [self initUI]; _serverIpTxt.text=kkServerUrl; _serverPortTxt.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 { // Animate the current view out of the way if(!keyboardShow){ [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); }];} keyboardShow=YES; } /** 异常键盘 */ -(void)keyboardWillHide { // Animate the current view back to its original position if(keyboardShow){ [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); }];} keyboardShow=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]; _serverIpTxt=[[UITextField alloc]init]; _serverIpTxt.frame=CGRectMake(CGRectGetMaxX(ipImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(ipImg.frame) + 10), 20); _serverIpTxt.font = [UIFont systemFontOfSize:TextFontOfSize]; _serverIpTxt.textAlignment = NSTextAlignmentCenter; [contentView addSubview: _serverIpTxt]; _serverIpTxt.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]; _serverPortTxt=[[UITextField alloc]init]; _serverPortTxt.font = [UIFont systemFontOfSize:TextFontOfSize]; _serverPortTxt.textAlignment = NSTextAlignmentCenter; _serverPortTxt.placeholder=@"服务器端口"; _serverPortTxt.frame=CGRectMake(CGRectGetMaxX(portImg.frame)+10,lbly, self.view.frame.size.width - 2*( CGRectGetMaxX(portImg.frame) + 10), 20); [contentView addSubview: _serverPortTxt]; 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=[_serverIpTxt.text stringByReplacingOccurrencesOfString:@" " withString:@""]; kkServerPort=[_serverPortTxt.text stringByReplacingOccurrencesOfString:@" " withString:@""]; [self dismissViewControllerAnimated:YES completion:nil]; } /** 返回按钮 */ -(void)goBack{ [self dismissViewControllerAnimated:YES completion:nil]; } @end