iOS 根据父视图布局的方法 以及实现 Scrollview 拉动 遮罩输入框问题解决
来源:互联网 发布:windows loader 2.1.6 编辑:程序博客网 时间:2024/05/21 06:29
1. iOS 根据父视图布局设定对应的x y点,然后设置当前视图的所在位置根据比例设置。
2. iOS 通过ScrollView 设置时限拉动效果 iOS 7.0 不需要减掉 顶部状态栏的高度 20, 但是7.0 以后需要减掉状态栏
3. iOS 遮罩文本框问题。
//// SecondController.m// HappyApp//// Created by LiShijia on 14/11/19.// Copyright (c) 2014年 com.johnli. All rights reserved.//#import "SecondController.h"#import "ViewController.h"#import <UIKit/UIKit.h>@implementation SecondController-(void) viewDidLoad{ [self.view setBackgroundColor:[UIColor whiteColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil]; // CGPoint bottomOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height - self.scrollView) // [self.navigationController.toolbar setHidden:YES]; _scroller = [[UIScrollView alloc ] initWithFrame: self.view.bounds]; _scroller.frame = self.view.frame; NSLog(@"before return the height %.f",_scroller.frame.size.height); // [_scroller setBackgroundColor: [UIColor redColor]]; CGSize size; size = self.view.frame.size; size.height = self.view.frame.size.height - 44.f - 19.f; _scroller.contentSize = size; NSLog(@"the frame bounds %f",self.navigationController.toolbar.frame.size.height); _scroller.bounces = YES; [self.view addSubview: _scroller]; [self addUser]; [self addPwd]; [self addPopButton]; }//can key when you click return or finish-(void) backUpTap{ [self.view endEditing:YES]; }- (void) textFieldDidBeginEditing:(UITextField *)textField{ float viewY = textField.bounds.origin.y; // //// self.view.window.bounds // _scroller.contentSize = CGSizeMake(rect.size.width,rect.size.height + 10); // //原始滑动距离增加键盘高度// CGPoint pt = [textField convertPoint:CGPointMake(0, 0) toView:_scroller]; // //把当前的textField的坐标映射到scrollview上 // float navBarheight = self.navigationController.navigationBar.bounds.size.height; NSLog(@"offset y %f",_scroller.contentOffset.y); NSLog(@"view y %f",viewY); NSLog(@"nav bar height %f",navBarheight); if(_scroller.contentOffset.y-viewY+navBarheight<=0){ // //判断最上面不要去滚动 //// [_scroller setContentOffset:CGPointMake(0, viewY-navBarheight) animated:YES]; [_scroller setContentOffset:CGPointMake(0, viewY-navBarheight) animated:YES]; } }//- (void) textFieldDidBeginEditing:(UITextField *)textField{//// foucsTextField = textField;// float viewY = textField.bounds.origin.y;// //// self.view.window.bounds// CGRect rect = [UIScreen mainScreen].applicationFrame;// _scroller.contentSize = CGSizeMake(rect.size.width,rect.size.height +216);// //原始滑动距离增加键盘高度// CGPoint pt = [textField convertPoint:CGPointMake(0, 0) toView:_scroller];// //把当前的textField的坐标映射到scrollview上// // float navBarheight = self.navigationController.navigationBar.//// if(_scroller.contentOffset.y-viewY+navBarheight<=0){// //判断最上面不要去滚动//// [_scroller setContentOffset:CGPointMake(0, viewY-navBarheight) animated:YES];// //[_scroller setContentOffset:CGPointMake(0, viewY-navBarheight) animated:YES];//// }// //}//- (void) keyboardWillShow { // NSLog(@"the keyboard will show %@",nofication); NSLog(@" the keyboard will show"); // CGPoint offet = CGPointMake(0, self.view.bounds.origin.y + 216);// // float offetHeigh = _userPwd.bounds.origin.y - 216;// // NSLog(@"offer %f",_userPwd.bounds.origin.y); // [_scroller setContentOffset:offet animated:YES]; }- (void) addUser{ //获取父视图对象的 x 以及 y 点 然后计算当前视图所排放的位置 CGRect urect = CGRectMake(_scroller.center.x * 0.2f, _scroller.center.y * 0.3f, 100, 50 ); UILabel * userLabel = [[UILabel alloc] initWithFrame:urect]; [userLabel setText:@"UserName"]; [_scroller addSubview:userLabel]; // NSLayoutConstraint *layout = [NSLayoutConstraint constraintWithItem:userLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_scroller attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0];// NSLog(@"ssssssss %.f",userLabel.frame.origin.y); urect.origin.x = _scroller.center.x * 0.8f; urect.origin.y = _scroller.center.y * 0.35f; urect.size.height = 20; urect.size.width = _scroller.frame.size.width * 0.54f;; UITextField * userField = [[UITextField alloc] initWithFrame: urect]; [userField setBackgroundColor:[UIColor redColor]]; userField.borderStyle = UITextBorderStyleRoundedRect; // [userField addTarget:self action:@selector(backUpTap) forControlEvents:UIControlEventEditingDidEndOnExit]; userField.delegate = self; [_scroller addSubview:userField]; }//add user pwd lable-(void) addPwd{ CGRect prect = CGRectMake(_scroller.center.x * 0.2f, _scroller.center.y * 0.5f, 150, 50 ); UILabel * pwdLable = [[UILabel alloc] initWithFrame:prect]; [pwdLable setText:@"Password"]; [_scroller addSubview:pwdLable]; prect.origin.x = _scroller.center.x; prect.origin.y = _scroller.center.y * 0.55f; prect.size.height = 20; prect.size.width = 100; _userPwd = [[UITextField alloc] initWithFrame:prect]; [_userPwd setBackgroundColor:[UIColor redColor]]; _userPwd.secureTextEntry = YES; _userPwd.borderStyle = UITextBorderStyleRoundedRect; _userPwd.delegate = self; // [userPwd addTarget:self action:@selector(backUpTap) forControlEvents:UIControlEventEditingDidEndOnExit]; [_scroller addSubview:_userPwd];}- (void) addPopButton{ UIButton * popButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 400, 100, 50)]; [popButton setBackgroundColor:[UIColor redColor]]; [popButton setTitle:@"Login" forState:UIControlStateNormal]; [popButton addTarget:self action:@selector(popLastController) forControlEvents:UIControlEventTouchUpInside]; [_scroller addSubview:popButton];}-(BOOL) textFieldShouldReturn:(UITextField *) textField { NSLog(@"you are clicing the return key"); [self.view endEditing:YES]; //开始动画 [UIView beginAnimations:nil context:nil]; //设定动画持续时间 [UIView setAnimationDuration:0.3]; _scroller.frame = self.view.frame; NSLog(@"after return the height %.f",_scroller.frame.size.height); CGSize size; size = self.view.frame.size; size.height = self.view.frame.size.height - 44.f - 19.f; // [_scroller setContentSize: size]; //动画结束 [UIView commitAnimations]; return YES;}- (void) popLastController{ //[self.navigationController popViewControllerAnimated:YES]; //ViewController * vc = (ViewController *)[self.navigationController.viewControllers objectAtIndex:0]; [self.navigationController popToRootViewControllerAnimated:YES];// [self.navigationController popToViewController:vc animated:YES]; }@end
0 0
- iOS 根据父视图布局的方法 以及实现 Scrollview 拉动 遮罩输入框问题解决
- iOS scrollView的自动布局
- NestedScrollView 以及ScrollView中 布局自动wrap_parent问题解决
- 关于IOS键盘遮住输入框以及关闭的方法。
- iOS scrollview的实现
- ios自动布局autolayout 实现scrollView
- android 输入顶起输入框下被隐藏布局的实现方法
- ios之让输入键盘隐藏消失的方法/以及系统通知的实现
- 关于利用js实现css切换布局视图的方法
- ScrollView嵌套ListView的问题解决方法
- scrollView中视图滚动调用的方法
- iOS中ScrollView相对布局的使用
- iOS-两个scrollView联动(上下两个scrollView布局的情况)
- IOS 子视图touch,父视图Ges手势冲突问题解决方法
- ScrollView 之 实现视图的循环显示
- Android学习Scroller(四)——实现拉动后回弹的布局
- iOS UITableView:section的Header以及Footer不悬浮停留在屏幕的方法(非在scrollView代理实现的方法)
- 深入理解布局容器绘制,解决ListView嵌套listview,或者ScrollView嵌套listview,gridview的高度问题解决方法
- SQLServer datediff () 函数 使用例子
- 开源的推荐系统简介TOP 10
- hdu2577——How to Type
- ASP判断身份证号码输入是否正确函数代码
- MySQL 5.6安装及配置详细图解
- iOS 根据父视图布局的方法 以及实现 Scrollview 拉动 遮罩输入框问题解决
- 连接真机出现的错误
- Android 主线程与子线程的通信 By Handler and Message
- ASP判断手机号码输入是否正确正则代码
- 建立C++内存管理的层次感
- 一个表单同时提交到两个不同的页面
- C API--linux上c语言读取数据库内容(mysql)
- UML之关系
- uboot-->kernel