美文网首页
YYText设置内边距+键盘处理

YYText设置内边距+键盘处理

作者: 守护地中海的花 | 来源:发表于2019-05-21 11:51 被阅读0次
  • 设置内边距 kvc
    效果图


    image.png
       YYTextView *view = [[YYTextView alloc]init];
        [self addSubview:view];
        view.backgroundColor = kColor180;
        view.placeholderFont = [UIFont systemFontOfSize:16*ADAPTER_WIDTH weight:UIFontWeightRegular];
        view.placeholderText = @"删除话题原因~";
        view.placeholderTextColor = kColor160;
        view.font = [UIFont systemFontOfSize:16*ADAPTER_WIDTH weight:UIFontWeightRegular];
        view.textColor = [UIColor blackColor];
        view.frame = CGRectMake(13*ADAPTER_WIDTH, 98*ADAPTER_WIDTH, self.width - 26*ADAPTER_WIDTH, 206*ADAPTER_WIDTH);
        view.layer.cornerRadius = 5*ADAPTER_WIDTH;
        view.layer.masksToBounds = YES;
        /*
         @property (nonatomic) IBInspectable CGFloat insetTop_;
         @property (nonatomic) IBInspectable CGFloat insetBottom_;
         @property (nonatomic) IBInspectable CGFloat insetLeft_;
         @property (nonatomic) IBInspectable CGFloat insetRight_;
         */
        [view setValue:@(20*ADAPTER_WIDTH) forKey:@"insetTop_"];
        [view setValue:@(20*ADAPTER_WIDTH) forKey:@"insetBottom_"];
        [view setValue:@(8*ADAPTER_WIDTH) forKey:@"insetLeft_"];
        [view setValue:@(8*ADAPTER_WIDTH) forKey:@"insetLeft_"];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickTextView:)];
        view.userInteractionEnabled = YES;
        [view addGestureRecognizer:tap];
  • 核心代码 键盘
@property(nonatomic,assign)BOOL keyboardJump;//YES 键盘弹起 NO 键盘没有弹起

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

#pragma mark - 处理键盘
- (void)keyboardWillChangeFrame:(NSNotification *)noti
{
    CGRect keyBoardFrame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];
    CGFloat duration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey]floatValue];
    //0.250000
    CGFloat moreMargin = 103*ADAPTER_WIDTH;
    CGFloat top = keyBoardFrame.origin.y == HEIGHT ? (HEIGHT - kSelfHeight) : (HEIGHT - kSelfHeight - keyBoardFrame.size.height + moreMargin);
    self.keyboardJump = keyBoardFrame.origin.y == HEIGHT ? NO : YES ;
    [UIView animateWithDuration:duration animations:^{
        self.top = top;
    }];
}

[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self];
  • 取消键盘响应:点击父类View 键盘下退(点击textView键盘不响应 所以textView也要添加手势)、点击父类View的黑色背景
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickSelf:)];
self.userInteractionEnabled = YES;
[self addGestureRecognizer:tap];


- (void)clickSelf:sender
{
    [self.textView resignFirstResponder];
}
- (void)clickTextView:sender
{
    [self.textView becomeFirstResponder];
}

相关文章

  • YYText设置内边距+键盘处理

    设置内边距 kvc效果图image.png 核心代码 键盘 取消键盘响应:点击父类View 键盘下退(点击text...

  • 前端Day11

    CSS内边距 内边距是设置盒子与子盒子之间的距离。 pading: 10px; 设置上下左右都是10px的内边距。...

  • Android TextView边界表情显示不全

    试试给TextView是设置 内边距,我这边竟然可以了。 设置右侧内边距 30dp

  • UITextView

    设置UITextView 内边距

  • cell的全屏穿透效果

    设置tabView的尺寸大小为全屏尺寸 设置tabView的内边距contentInset,顶部内边距等于导航栏+...

  • UICollectionView cell之间的间隔记录

    一、设置collectionView的内边距 橘色表示内边距,分别为10 二、只设置平行方向的间距 三、只设置垂直...

  • HTML+CSS进阶

    输入 设置单一边距:padding-top(上内边距)、padding-bottom(下内边距)、padding-...

  • html + CSS学习笔记 1.padding关键字

    1、CSS 功能margin:用于设置外边距;而padding用于设置内边距。 这个表格单元的每个边拥有相等的内边...

  • css盒子-内外边距

    内边距(padding) padding属性用于设置内边距。 是指 边框与内容之间的距离。 padding-to...

  • 盒模型

    为元素应用内边距 为元素应用外边距 设置元素的尺寸 处理溢出image text 控制元素的可见性visibili...

网友评论

      本文标题:YYText设置内边距+键盘处理

      本文链接:https://www.haomeiwen.com/subject/ohidzqtx.html