资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

ios开发键盘高度,ios键盘设置大小

iOS改变自定义键盘高度

在自定义键盘的时候,碰到要根据横竖屏,然后改变自定义键盘高度的需求,但是发现,无论使用autolayout还是设置frame去改变高度,都没有反应。后面经过查阅,才知道有个Intrinsic Content Size属性。可以设置视图的自定义大小。

创新互联公司专注于荷塘企业网站建设,响应式网站开发,成都商城网站开发。荷塘网站建设公司,为荷塘等地区提供建站服务。全流程按需网站设计,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

关于 intrinsicContentSize 及 约束优先级/content Hugging/content Compression Resistance的详解,参考如下博客:

下面是自己的简单记录:

改变自定义键盘的高度可以设置键盘View的视图Intrinsic Content Size属性。

先设置属性:

然后再调用方法:

大概demo如下:

苹果键盘怎么调大小

在苹果手机的键盘设置内,进入到键盘高度功能内向上拖动,即可调节苹果手机键盘的大小。

工具/原料:iPhone12、ios14.1.7。

1、点击工具箱。选择输入法右上角的工具箱图标。

2、点击键盘高度。选择键盘高度的图标进入。

3、设置大小。向上拖动设置键盘的大小。

4、点击完成。选择下方的完成选项即可。

怎么使iOS中的键盘适应高度变化

在ios开发时我们会遇到键盘高度无法适应的问题,这时候该怎么解决呢?下面由我教大家怎么解决iOS中的键盘高度变化的问题。

    完美解决iOS中的键盘适应高度变化的 方法

#pragma mark - reg unreg notification

- (void)regNotification

{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];

}

- (void)unregNotification

{

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];

}

#pragma mark - notification handler

- (void)keyboardWillChangeFrame:(NSNotification *)notification

{

NSDictionary *info = [notification userInfo];

CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];

CGRect beginKeyboardRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];

CGRect endKeyboardRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];

CGFloat yOffset = endKeyboardRect.origin.y - beginKeyboardRect.origin.y;

CGRect inputFieldRect = self.inputTextField.frame;

CGRect moreBtnRect = self.moreInputTypeBtn.frame;

inputFieldRect.origin.y += yOffset;

moreBtnRect.origin.y += yOffset;

[UIView animateWithDuration:duration animations:^{

self.inputTextField.frame = inputFieldRect;

self.moreInputTypeBtn.frame = moreBtnRect;

}];

}

通过获取键盘消息的开始状态、结束状态,以及变化周期,可以计算出具体的Y偏移,从而在相同时间里做相同偏移量。

猜你喜欢:

2. 怎样把电脑上的照片导入iphone

3. iphone照片怎么导入电脑

4. 电脑ipad模拟器的安装方法

5. 安卓程序员必备的开发工具

6. iPhone5s怎么刷机

IOS 开发键盘高度是多少

键盘高度是一个非固定值,以前都是216,但是现在由于介入太多的第三方键盘,高度五花八门,所以你只能通过键盘弹出的监听来获取键盘高度。

iOS 监听键盘的弹出,收起,并且拿到键盘的高度

监听当键盘将要出现时

OC版

[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];

[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification object:nil];

- ( void )keyboardWillShow:(NSNotification *)notification

{

//    //获取键盘的高度

//    NSDictionary *userInfo = [notification userInfo];

//    NSValue *value = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];

//    CGRect keyboardRect = [value CGRectValue];

//    int height = keyboardRect.size.height;

CGFloatcurkeyBoardHeight = [[[notificationuserInfo]objectForKey:@"UIKeyboardBoundsUserInfoKey"]CGRectValue].size.height;

      CGRectbegin = [[[notificationuserInfo]objectForKey:@"UIKeyboardFrameBeginUserInfoKey"]CGRectValue];

      CGRectend = [[[notificationuserInfo]objectForKey:@"UIKeyboardFrameEndUserInfoKey"]CGRectValue];

    // 第三方键盘回调三次问题,监听仅执行最后一次

    if (begin.size.height0 (begin.origin.y-end.origin.y0)){

      CGFloatkeyBoardHeight = curkeyBoardHeight;

      NSLog(@"第三次:%f",keyBoardHeight);

        [UIView  animateWithDuration:0.05 animations:^{

          self .countLb_bottomH.constant= keyBoardHeight+10*sizeScale;

      }];

    }

}

- ( void )keyboardWillHide:(NSNotification*)notificationswift版

{

//获取键盘的高度

NSDictionary*userInfo = [notificationuserInfo];

NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

CGRectkeyboardRect = [valueCGRectValue];

int height = keyboardRect.size.height;

self .countLb_bottomH.constant = 12*sizeScale;

}

NotificationCenter.default.addObserver(self,selector:#selector(keyBoardShow(noty:)),name:Notification.Name.UIKeyboardWillShow,object:nil)

NotificationCenter.default.addObserver(self,selector:#selector(keyBoardHidden(noty:)),name:Notification.Name.UIKeyboardWillHide,object:nil)

@objcfunckeyBoardShow(noty:Notification){guardletuserInfo=noty.userInfoelse{return}letvalue=userInfo["UIKeyboardFrameBeginUserInfoKey"]as!NSValueletkeyboardRect=value.cgRectValueletkeyboradHeight=keyboardRect.size.height}

@objcfunckeyBoardShow(noty:Notification){guardletuserInfo=noty.userInfoelse{return}letvalue=userInfo["UIKeyboardFrameEndUserInfoKey"]as!NSValueletkeyboardRect=value.cgRectValueletkeyboradHeight=keyboardRect.size.height}

参考:


当前名称:ios开发键盘高度,ios键盘设置大小
网页路径:http://cdkjz.cn/article/dscooii.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220