搜索
您的当前位置:首页正文

自定义实现@someone 的功能思路(二)

来源:二三娱乐

现在需要开始输入了

  • 首先文字


    3.jpeg

    前文提到我们输入部分用的是UITextView ,所以我们要遵守他的协议和方法,

UITextViewDelegate
//每当键盘输入内容的时候 都会有监听
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
//输入结束的时候调用
- (void)textViewDidEndEditing:(UITextView *)textView
//输入改变的时候调用
- (void)textViewDidChange:(UITextView *)textView

看上一节 第一个部分的要求 需要不限制输入 就是输入多少都需要显示,textview的frame就要变大,所以:(这个地方个人觉得也应该限制高度,就是最大到多大,但是UI没有要求,就暂时没加)

- (void)textViewDidChange:(UITextView *)textView
{
    [self reloadTextViewFrame:textView];
}
- (void)reloadTextViewFrame:(UITextView *)textView
{
    CGRect frame = textView.frame;
    CGSize constraintSize = CGSizeMake(frame.size.width, MAXFLOAT);
    CGSize size = [textView sizeThatFits:constraintSize];
    if (size.height <= frame.size.height) {
    } else {
       //这里限制最小大小就是30 
        if (size.height <= 30) {
            size.height = 30;
            textView.scrollEnabled = NO; // 不允许滚动

        } else {
            textView.scrollEnabled = YES; // 允许滚动
        }
    }
    textView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);
// textView.frame改变以后 他下面的两个view 也要跟着下移 
    _lineView.frame = CGRectMake(15, self.discussView.bottom + 15, SCREEN_WIDTH - 15, 0.5);
    _transmitbgView.frame = CGRectMake(15, self.lineView.bottom + 15, SCREEN_WIDTH - 30, 196 * WIDTH_SCALE);
}

于是我们有一下效果 :


4.jpeg
  • 表情键盘部分


    5.jpeg

这是我们的小伙伴自己写的表情键盘 具体实现不便透露,他给我提供了一下接口

typedef NS_OPTIONS(NSUInteger, DDEmotionInputViewType) {
    DDEmotionInputViewTypeShowCamera = 1 << 0,
    DDEmotionInputViewTypeShowAt = 1 << 1,
};


@interface DDEmotionInputView : UIControl

/**
 初始化方法
 
 @param type 键盘类型
 @param textView textView
 @param textViewDelegate textView的代理对象
 @return 实例对象
 */
- (instancetype)initWithType:(DDEmotionInputViewType)type textView:(UITextView *)textView textViewDelegate:(nullable id<UITextViewDelegate>)textViewDelegate;

/**
 初始化方法
 
 @param type 键盘类型
 @param textField textView
 @param textFieldDelegate textView的代理对象
 @return 实例对象
 */

- (instancetype)initWithType:(DDEmotionInputViewType)type textField:(UITextField *)textField textFieldDelegate:(nullable id<UITextFieldDelegate>)textFieldDelegate;

- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
/**
 camera事件
 */
@property (nonatomic, copy) void (^cameraPressedBlock)(void);

/**
 @事件
 */
@property (nonatomic, copy) void (^atPressedBlock)(void);

/**
 发送事件
 */
@property (nonatomic, copy) void (^sendEmotionBlock)(void);

/**
 表情键盘点击事件
 */
@property (nonatomic, copy) void (^emotionPressedBlock)(NSString *emotion);

/**
 表情键盘删除事件
 */
@property (nonatomic, copy) void (^emotionDeletedBlock)(void);

@end

我自己调用的时候

- (DDEmotionInputView *)inpuview
{
    if (!_inpuview) {
        _inpuview = [[DDEmotionInputView alloc] initWithType:DDEmotionInputViewTypeShowAt textView:self.discussView textViewDelegate:self.discussView.delegate];
        WS(weakSelf);
        _inpuview.atPressedBlock = ^{
            //调用 @ 内容
        };

        _inpuview.emotionPressedBlock = ^(NSString *_Nonnull emotion) {
                NSMutableString * str = [[NSMutableString alloc]initWithString:weakSelf.discussView.text];
                [str appendString:[NSString stringWithFormat:@"%@",emotion]];
                weakSelf.discussView.text =str;
        };

        _inpuview.emotionDeletedBlock = ^{
        };
    }
    return _inpuview;
}

就可以了
效果如下:


6.jpeg
  • @选人部分
    点击@ 跳转选人页面


    7.jpeg

这个选人界面也是工程原有的功能,具体代码就不赘述了,里面都是测试账号,名字奇怪,无需介意,😝。
选完人,点击确定会返回,并且带回选中的人的数组。

- (void)atVCmake:(AtSelectType)type
{
    DD_ContactSelect_VC *vc = [[DD_ContactSelect_VC alloc] init];
    vc.selectModel.maxCount = COMPANY_DEFAULT_USERCOUNT;
    vc.title = @"提醒谁看";
    vc.navigationController.title = @"提醒谁看";
    @CuteWS(self);
    @CuteWS(vc);
    vc.selectedFinishBlock = ^(NSArray *selectedArray) {
        //就是这个数组  selectedArray
        [vcWeak.navigationController popToViewController:self animated:YES];
        return YES;
    };

    [self.navigationController pushViewController:vc animated:YES];
}

那么接下来就需要把@选人界面带过来的人加入输入框,并且记住都带了谁过来,以便给他发私信啊。

    //这里选过的人,怕是还会被选中,所以这里弄了一个去重 防止重复添加某一个人 导致    @某人 好几次
       NSMutableArray *norepeatArr = [[NSMutableArray alloc] init];
            for (Person *person in selectedArray) {
                if ([selfWeak.aLLNameArray containsObject:person]) {
                } else {
                    [selfWeak.aLLNameArray addObject:person];
                    [norepeatArr addObject:person];
                }
            }

            if (norepeatArr.count > 0) {
                [selfWeak atStringAppendingWithArray:norepeatArr];
            }
        }

所以接下来关键了 怎么把这个@加到textView中,并且具有@的特性,就是可以一下删掉,高亮等等。

请看下集...

Top