b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

iOS防键盘阻塞示例

电脑杂谈  发布时间:2020-06-09 14:22:27  来源:网络整理

ios 解决键盘遮挡问题_ios 解决键盘遮挡问题_为什么我的电脑动键盘会自动关机有什么解决的办法

时间: 2019-04-12

ios 解决键盘遮挡问题_为什么我的电脑动键盘会自动关机有什么解决的办法_ios 解决键盘遮挡问题

本文向您介绍iOS防键盘阻塞的示例ios 解决键盘遮挡问题,主要包括iOS防键盘阻塞的使用案例,应用技巧,基本知识要点和注意事项的汇总,具有一定的参考价值,需要的朋友可以引用它.

ios 解决键盘遮挡问题_为什么我的电脑动键盘会自动关机有什么解决的办法_ios 解决键盘遮挡问题

当我们在UITextField中输入数据时,我们通常会弹出键盘遮挡界面. 解决方案是: 在弹出键盘时将整个UIVIew向上移动ios 解决键盘遮挡问题,并在键盘消失时恢复UIVIew.

为什么我的电脑动键盘会自动关机有什么解决的办法_ios 解决键盘遮挡问题_ios 解决键盘遮挡问题

示例代码如下:

为什么我的电脑动键盘会自动关机有什么解决的办法_ios 解决键盘遮挡问题_ios 解决键盘遮挡问题

@interface ViewController ()<UITextFieldDelegate>
@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<UITouch *> *)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反键盘阻止示例是我与您共享的所有内容. 我希望为您提供参考,也希望您支持该脚本主页.


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shumachanpin/article-239527-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 张芷兰
        张芷兰

        美欧联盟与中俄暗盟角力中东

      热点图片
      拼命载入中...