电脑开机左上角光标闪很久一直闪,我先前因为装了个win10系统感到不适应,就想装

tableview初始化时- (UITableView *)tableView {
if (!_tableView) {
UITableViewController* tvc=[[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[self addChildViewController:tvc];
_tableView=tvc.tableV
_tableView.delegate =
_tableView.dataSource =
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleL
return _tableV
原理是使用UITableViewController来代替UITableView,UITableViewController中的tableview可以自适应键盘高度来改变tableview的额外高度
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1030次
排名:千里之外
原创:14篇
(1)(3)(3)(2)(1)(6)textField被虚拟键盘挡住的3种解决方法
经常会遇到以下情况,textField被键盘挡住的情况,。
RootViewController.h 中:
#import &UIKit/UIKit.h&
@interface RootViewController : UIViewController&UITextFieldDelegate& {
UITextField *textField1;
UITextField *textField2;
@property (nonatomic,retain) UITextField *textField1;
@property (nonatomic ,retain) UITextField *textField2;
-(IBAction)backgroundTap:(id)
RootViewController.m 中:
#import "RootViewController.h"
@implementation RootViewController@synthesize textField1;@synthesize textField2;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad {
[super viewDidLoad];
UIControl *_back = [[UIControl alloc] initWithFrame:self.view.frame];
_back.backgroundColor = [UIColor grayColor];
self.view = _
[_back release];
[(UIControl *)self.view addTarget:self action:@selector(backgroundTap:) forControlEvents:UIControlEventTouchDown];
textField1 = [[UITextField alloc] initWithFrame:CGRectMake(20, 300, 200, 30)];
textField1.backgroundColor = [UIColor clearColor];
textField1.borderStyle = UITextBorderStyleRoundedR
textField1.textColor = [UIColor redColor];
textField1.delegate =
[self.view addSubview:textField1];
textField2 = [[UITextField alloc] initWithFrame:CGRectMake(20, 30, 200, 30)];
textField2.backgroundColor = [UIColor clearColor];
textField2.borderStyle = UITextBorderStyleRoundedR
textField2.textColor = [UIColor redColor];
textField2.delegate =
[self.view addSubview:textField2];
}#pragma mark - 解决虚拟键盘挡住UITextField的方法
- (void)keyboardWillShow:(NSNotification *)noti
{ //键盘输入的界面调整 //键盘的高度float height = 216.0;
CGRect frame = self.view.
frame.size = CGSizeMake(frame.size.width, frame.size.height - height);
[UIView beginAnimations:@"Curl"context:nil];//动画开始 [UIView setAnimationDuration:0.30];
[UIView setAnimationDelegate:self];
[self.view setFrame:frame];
[UIView commitAnimations];
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{ // When the user presses return, take focus away from the text field so that the keyboard is dismissed. NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
CGRect rect = CGRectMake(0.0f, 20.0f, self.view.frame.size.width, self.view.frame.size.height);
self.view.frame =
[UIView commitAnimations];
[textField resignFirstResponder];return YES;
- (void)textFieldDidBeginEditing:(UITextField *)textField
CGRect frame = textField.int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0);//键盘高度216NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
[UIView setAnimationDuration:animationDuration];float width = self.view.frame.size. float height = self.view.frame.size. if(offset & 0)
CGRect rect = CGRectMake(0.0f, -offset,width,height);
self.view.frame =
[UIView commitAnimations];
#pragma mark - 触摸背景来关闭虚拟键盘
-(IBAction)backgroundTap:(id)sender
{// When the user presses return, take focus away from the text field so that the keyboard is dismissed. NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
CGRect rect = CGRectMake(0.0f, 20.0f, self.view.frame.size.width, self.view.frame.size.height);
self.view.frame =
[UIView commitAnimations];
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
#pragma mark -
- (void)didReceiveMemoryWarning {// Releases the view if it doesn't have a superview.[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.}
- (void)viewDidUnload {
[super viewDidUnload];// Release any retained subviews of the main view.// e.g. self.myOutlet =}
- (void)dealloc {
[textField1 release];
[textField2 release];
[super dealloc];
RootViewController.m
中的backgroundTap:,用来实现触摸背景来关闭虚拟键盘。
这个方法用的时候首先把RootViewController上的view改成UIControl,然后通过UIControl的事件UIControlEventTouchDown来上面的方法backgroundTap:
下面的代码:
UIControl *_back = [[UIControl alloc] initWithFrame:self.view.frame];
_back.backgroundColor = [UIColor grayColor];
self.view = _
[_back release];
[(UIControl *)self.view addTarget:self action:@selector(backgroundTap:) forControlEvents:UIControlEventTouchDown];
总结:解决textField被键盘挡住的的方法有三个:
- (void)keyboardWillShow:(NSNotification *)//调整虚拟键盘与self.view之间的关系。
- (BOOL)textFieldShouldReturn:(UITextField *)textF//触摸键盘上的return键时关闭虚拟键盘
- (void)textFieldDidBeginEditing:(UITextField *)textF//当编辑文本的时候,如果虚拟键盘挡住了textField,整个view就会向上移动。移动范围是一个键盘的高度216。
UITextField键盘自适应
最近转入ios开发,发现ios的UITextField如果在屏幕的最底部的时候,键盘不能自动的调整界面的布局,需要手动的调整位置才可以,所以自己研究和拿着笔话,想写一个通用的方法来实现每一个界面自动适配键盘的位置,这样的话,不用每一个界面去操作界面的位置了,具体的解决方案如下:
1. 先创建一个ViewController 继承自 UIViewController,让以后的每一个界面继承这个界面,在这个界面里面实现一个委托,代码如下:
2.在这个BaseViewCOntroller.m文件中,现实UITextFieldDelegate中的两个方法,textFieldDidBeginEditing(开始编辑UITextField和&textFieldDidEndEditing(结束编辑UITextField),大家都知道,iphone的键盘都是固定的,都是系统自带的,没有第三方的输入法的,所以键盘的高度是固定的216,我们只要在开始编辑的时候,计算一下当前的UITextField的所在高度相对底部是否有216(就是UITextField的底部边缘相对屏幕的底部是否有216个长度),如果不够216,就需要把整体的view上移达到216高度即可;当我们结束编辑的时候,把之前增加的高度相反操作即可,代码如下:
//设置调整界面的动画效果//设置调整界面的动画效果
3.在上面的代码中,我们已经增加了委托对UITextField的编辑监听,下面我们就要让我们的子类UIViewController去监听委托
IDNameField是我继承BaseViewController的子类UIViewController中的一个UITextField,只要实现了上面的操作,我们的UITextField就可以在每一个界面实现自动适配调整界面,达到防止键盘挡住UITextField的效果了,
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。ios在tableview上添加textField后避免键盘遮挡的解决方案 - 简书
<div class="fixed-btn note-fixed-download" data-toggle="popover" data-placement="left" data-html="true" data-trigger="hover" data-content=''>
写了13679字,被47人关注,获得了102个喜欢
ios在tableview上添加textField后避免键盘遮挡的解决方案
最近做项目的时候需要在tableview上添加很多textField输入框,但是当键盘弹出后会遮挡输入框,后来在网上找过很多方案,但皆不尽如人意。大多是使用使用监听事件,通过监听键盘事件来调整UITableView的frame。但是计算偏移量不是很精确,不是偏移的多了就是偏移的少了,而且还特别麻烦!如下图,当我准备在输入邮箱的位置输入内容,结果会被键盘挡住:
-8BA8-4D6E-AF60-B6A3CC3C4498.png
ED8-4D75-82D1-BB.png
最近在网上找到了更好的解决办法,见代码:
-(UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight-64) style:UITableViewStyleGrouped];
//处理键盘遮挡问题
UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[self addChildViewController:tvc];
_tableView = tvc.tableV
-----------&加上以上三行代码完美解决问题!
_tableView.backgroundColor = KGrayC
_tableView.delegate =
_tableView.dataSource =
_tableView.rowHeight = 55;
_tableView.separatorStyle = 0;//去掉分割线
_tableView.tableHeaderView = [self headView];
_tableView.tableFooterView = [self footerView];
return _tableV
1CBF703E-095C-46BB-AE4B-E79CD064745A.png
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
选择支付方式:Pages: 1/3
主题 : 如何实现被键盘遮挡时,带有textfield的tableview自动上移
级别: 骑士
可可豆: 2029 CB
威望: 2029 点
在线时间: 1291(时)
发自: Web Page
如何实现被键盘遮挡时,带有textfield的tableview自动上移&&&
我看到有地方说,在ios4以后当UITableViewCell里有UITextfield,且输入时键盘遮盖了UITextField时,UITableView会自动上移UIcatalog例子也是有这个效果的,但是我自己用代码实现的UITableView没有这个上移效果请问需要什么其他设置吗
级别: 侠客
可可豆: 1070 CB
威望: 1069 点
在线时间: 253(时)
发自: Web Page
再键盘出现时,将frame上移....键盘隐藏时,将frame再调整回来 加个动画效果应该不错....
级别: 侠客
UID: 57113
可可豆: 532 CB
威望: 532 点
在线时间: 85(时)
发自: Web Page
如果你的controller是继承uitableviewcontroller就可以了,处理键盘弹出和消失的代码已经封装在uitableviewcontroller里了,如果不继承,那就用楼上的招儿
码累了吧,来,抽根烟,长寿
级别: 侠客
可可豆: 875 CB
威望: 875 点
在线时间: 61(时)
发自: Web Page
最正规的办法,用通知step 1:在进入视图的时候添加监视:(viewDidLoad什么的)// Observe keyboard hide and show notifications to resize the text view appropriately.&#160;&#160;&#160; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];&#160;&#160;&#160; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];step 2:在键盘动作的时候移动视图:- (void)keyboardWillShow:(NSNotification *)notification {&#160;&#160;&#160; &#160;&#160;&#160; /*&#160;&#160;&#160;&#160; Reduce the size of the text view so that it&#39;s not obscured by the keyboard.&#160;&#160;&#160;&#160; Animate the resize so that it&#39;s in sync with the appearance of the keyboard.&#160;&#160;&#160;&#160; */&#160;&#160;&#160; NSDictionary *userInfo = [notification userInfo];&#160;&#160;&#160; &#160;&#160;&#160; // Get the origin of the keyboard when it&#39;s displayed.&#160;&#160;&#160; NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];&#160;&#160;&#160; // Get the top of the keyboard as the y coordinate of its origin in self&#39;s view&#39;s coordinate system. The bottom of the text view&#39;s frame should align with the top of the keyboard&#39;s final position.&#160;&#160;&#160; CGRect keyboardRect = [aValue CGRectValue];&#160;&#160;&#160; keyboardRect = [self.view convertRect:keyboardRect fromView:nil];&#160;&#160;&#160; &#160;&#160;&#160; CGFloat keyboardTop = keyboardRect.origin.y;&#160;&#160;&#160; CGRect newTextViewFrame = self.view.&#160;&#160;&#160; newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y;&#160;&#160;&#160; &#160;&#160;&#160; // Get the duration of the animation.&#160;&#160;&#160; NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];&#160;&#160;&#160; NSTimeInterval animationD&#160;&#160;&#160; [animationDurationValue getValue:&animationDuration];&#160;&#160;&#160; &#160;&#160;&#160; // Animate the resize of the text view&#39;s frame in sync with the keyboard&#39;s appearance.&#160;&#160;&#160; [UIView beginAnimations:nil context:NULL];&#160;&#160;&#160; [UIView setAnimationDuration:animationDuration];&#160;&#160;&#160; &#160;&#160;&#160; textView.frame = newTextViewF&#160;&#160;&#160; [UIView commitAnimations];}- (void)keyboardWillHide:(NSNotification *)notification {&#160;&#160;&#160; &#160;&#160;&#160; NSDictionary* userInfo = [notification userInfo];&#160;&#160;&#160; &#160;&#160;&#160; /*&#160;&#160;&#160;&#160; Restore the size of the text view (fill self&#39;s view).&#160;&#160;&#160;&#160; Animate the resize so that it&#39;s in sync with the disappearance of the keyboard.&#160;&#160;&#160;&#160; */&#160;&#160;&#160; NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];&#160;&#160;&#160; NSTimeInterval animationD&#160;&#160;&#160; [animationDurationValue getValue:&animationDuration];&#160;&#160;&#160; &#160;&#160;&#160; [UIView beginAnimations:nil context:NULL];&#160;&#160;&#160; [UIView setAnimationDuration:animationDuration];&#160;&#160;&#160; &#160;&#160;&#160; textView.frame = self.view.&#160;&#160;&#160; &#160;&#160;&#160; [UIView commitAnimations];}step 3:在退出视图的时候注销通知viewDidUnload:[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];&#160;&#160;&#160; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];dealloc:[[NSNotificationCenter defaultCenter] removeObserver:self name:nil object:nil];这些代码是摘自apple sample code KeyboardAccessory.些许细节自己修改下就好了,比如那个textView
级别: 侠客
可可豆: 732 CB
威望: 732 点
在线时间: 132(时)
发自: Web Page
回 3楼(heibaipei) 的帖子
级别: 新手上路
可可豆: 50 CB
威望: 50 点
在线时间: 467(时)
发自: Web Page
- (BOOL)textFieldDidBeginEditing:(UITextField *)textField{&&&&UITableViewCell * cell=(UITableViewCell *)[[textField&&superview] superview];&&&&NSIndexPath *indexPath=[curTable indexPathForCell:cell];&&&&if (indexPath.section==0) {&&&&&&&&&&&&}else {&&&&&&&&[UIView beginAnimations:@&ResizeForKeyBoard& context:nil];&&&&&&&&[UIView setAnimationDuration:0.30f];&&&&&&&&&&point = curTable.&&&&&&&&curTable.center = CGPointMake(160, 120);&&&&&&&&[UIView commitAnimations];&&&&}&&&&return YES;}- (BOOL)textFieldDidEndEditing:(UITextField *)textField{&&&&UITableViewCell * cell=(UITableViewCell *)[[textField&&superview] superview];&&&&NSIndexPath *indexPath=[curTable indexPathForCell:cell];&&&&&&&&if (indexPath.section==0) {&&&&&&&&&&&&}else {&&&&&&&&[UIView beginAnimations:@&ResizeForKeyBoard& context:nil];&&&&&&&&[UIView setAnimationDuration:0.30f];&&&&&&&&&&&&&&&&&&curTable.center =&&&&&&&&[UIView commitAnimations];&&&&}&&&&return YES;}-(BOOL)textFieldShouldReturn:(UITextField *)textField{&&&&&&&&[textField resignFirstResponder];&&&&&&&&return YES;}
级别: 圣骑士
UID: 83792
可可豆: 2270 CB
威望: 1864 点
在线时间: 1208(时)
发自: Web Page
mark~~~~~~
有勇气踏出一步,就要要有勇气接受踏出所带来的一切
级别: 新手上路
可可豆: 139 CB
威望: 139 点
在线时间: 14(时)
发自: Web Page
mark~~~~~~
级别: 骑士
可可豆: 1789 CB
威望: 1789 点
在线时间: 99(时)
发自: Web Page
级别: 精灵王
可可豆: 4004 CB
威望: 4004 点
在线时间: 624(时)
发自: Web Page
mark~~~~~~
Pages: 1/3
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版

我要回帖

更多关于 开机黑屏左上角光标闪 的文章

 

随机推荐