精品专区-精品自拍9-精品自拍三级乱伦-精品自拍视频-精品自拍视频曝光-精品自拍小视频

網站建設資訊

NEWS

網站建設資訊

iOS如何實現防鍵盤遮擋

這篇文章主要介紹了iOS如何實現防鍵盤遮擋,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

創新互聯-專業網站定制、快速模板網站建設、高性價比溧陽網站開發、企業建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式溧陽網站制作公司更省心,省錢,快速模板網站建設找我們,業務覆蓋溧陽地區。費用合理售后完善,十年實體公司更值得信賴。

當我們在UITextField輸入數據時經常彈出鍵盤遮擋界面,解決方法是:在彈出鍵盤時將整個UIVIew向上移動,在鍵盤消失時,UIVIew還原。

實例代碼如下:

@interface ViewController ()
@property(nonatomic,strong)UITextField* tf;
@end
@implementation ViewController
- (void)viewDidLoad {
 [super viewDidLoad];
 self.tf = [[UITextField alloc]initWithFrame:CGRectMake(10, 600, 100, 20)];
 self.tf.delegate = self;
 self.tf.backgroundColor = [UIColor blackColor];
 [self.view addSubview:self.tf];

}
#pragma mark life Circle
-(void)viewWillAppear:(BOOL)animated{
 [super viewWillAppear:animated];

 //后臺切換到前臺通知
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground)name:UIApplicationWillEnterForegroundNotification object:nil];
 [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(keyboardWillHide:)
             name:UIKeyboardWillHideNotification
            object:nil];

 [self.view endEditing:YES];
}
- (void)applicationWillEnterForeground{
 [self.view endEditing:YES];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
 [self.view endEditing:YES];
}

#pragma mark UITextFieldDelegate
-(void)textFieldDidBeginEditing:(UITextField *)textField{

 //第一個cell不往上彈輸入框的位置
 // if(indexPath.row!=0){
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
 // }
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
}
#pragma mark 鍵盤操作
- (void)keyboardWillChange:(NSNotification *)note
{
 NSDictionary *userInfo = note.userInfo;
 CGFloat duration = [userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] doubleValue];
 CGRect keyFrame = [userInfo[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
 //這個64是我減去的navigationbar加上狀態欄20的高度,可以看自己的實際情況決定是否減去;
 CGFloat moveY = keyFrame.origin.y -self.tf.frame.origin.y-self.tf.frame.size.height;
 NSLog(@"%f",moveY);
 [UIView animateWithDuration:duration animations:^{
  self.view.transform = CGAffineTransformMakeTranslation(0, moveY);
 }];
}

- (void)keyboardWillHide:(NSNotification *)nsnotification
{
 [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
 [UIView animateWithDuration:0.2 animations:^{
  self.view.transform = CGAffineTransformMakeTranslation(0, 0);
 }];
}

@end

感謝你能夠認真閱讀完這篇文章,希望小編分享的“iOS如何實現防鍵盤遮擋”這篇文章對大家有幫助,同時也希望大家多多支持創新互聯,關注創新互聯行業資訊頻道,更多相關知識等著你來學習!


文章題目:iOS如何實現防鍵盤遮擋
當前網址:http://m.jcarcd.cn/article/jpiijp.html
主站蜘蛛池模板: 欧美三级不 | 国产免费日本高清 | 日韩第一页在线观看 | 3d漫画在线观看 | 91国产最| 国产精品首页熟女 | 国产又粗又 | 国产欧美综合一 | 奇奇上司妻 | 欧性猛交 | 国产在线观看一区 | 午夜绿帽 | 国产黑丝在线 | 国产美女精品 | 乱伦三级高清精 | 国产高清免费在线 | 91人人| 日本汚视频在线观 | 日韩在线一二三四区 | 国产情侣91在 | 国产精品主播视频 | 午夜福利区 | 国产观看| 日韩精品国| 日本a级高清影片 | 韩国免费一级a一片 | 午夜国产理论 | 国产欧美在线高清 | 区二区免费网站 | 国产有码在线观看 | 国产一区二区xxx | 国产精首页 | 福利资源视频 | 人人澡人 | 日韩午夜一级 | 国产v片在线播 | 国产色吧 | 国产狂喷潮在线播放 | 欧美日韩亚洲第 | 爱豆传媒免费播放 | 日本一二三本道 |