zoukankan      html  css  js  c++  java
  • 为UITextView添加通知..来检测UITextView内容的改变

      self.mTextView =[[UITextView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 100, 28)];
        self.mTextView.backgroundColor =[UIColor whiteColor];
        self.mTextView.delegate = self;
        self.mTextView.text = @"我来说几句....";
        [self.mSecondaryBackView addSubview:self.mTextView];
     
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChanged:) name:UITextViewTextDidChangeNotification object:nil];
     
    - (void)textDidChanged:(NSNotification *)notif //监听文字改变 换行时要更改输入框的位置
    {
        CGSize contentSize = self.mTextView.contentSize;
        UILabel *holdPlace = (UILabel *)[self.mTextView viewWithTag:1500];
        if (holdPlace) {
                holdPlace.text = @"";
        }

       
        if (contentSize.height > 140){
            return;
        }
        CGFloat minus = 3;
        CGRect selfFrame = self.mBackView.frame;
        CGFloat selfHeight = self.mTextView.superview.frame.origin.y * 2 + contentSize.height - minus + 2 * 2;
        CGFloat selfOriginY = selfFrame.origin.y - (selfHeight - selfFrame.size.height);
        selfFrame.origin.y = selfOriginY;
        selfFrame.size.height = selfHeight;
        self.mBackView.frame = selfFrame;
        self.mSecondaryBackView.frame =CGRectMake(10, 10, 230, selfHeight-20);
        NSLog(@"文字改变");
    }
  • 相关阅读:
    基础算法:两数之和
    adb常用命令食用方法
    C语言面试题
    C语言经典笔试题目
    嵌入式01 51单片机实验02 sfr和sbit bit和int char
    C语言 01 volatile关键字
    C++ 01 基础知识点
    嵌入式02 STM32 实验11 NVIC和中断总结
    嵌入式02 STM32 实验10 定时器中断
    嵌入式02 STM32 实验09 独立/窗口看门狗
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4849741.html
Copyright © 2011-2022 走看看