gpt4 book ai didi

ios - 如何检测 UITextView 中的图像删除

转载 作者:可可西里 更新时间:2023-11-01 04:45:54 25 4
gpt4 key购买 nike

如果我像这样将图像添加到 UITextView 中:

NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = image;

NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
[myString appendAttributedString:attrStringWithImage];

self.inputTextView.attributedText = myString;

然后我如何通过用户点击键盘上的后退按钮检测到图像已被删除?

我会使用下面的吗?

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

如果是,怎么做到的?

最佳答案

我这样做了:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
[self.textView.attributedText enumerateAttribute:NSAttachmentAttributeName
inRange:NSMakeRange(0, self.textView.attributedText.length)
options:0
usingBlock:^(id value, NSRange imageRange, BOOL *stop){
if (NSEqualRanges(range, imageRange) && [text isEqualToString:@""]){
//Wants to delete attached image
}else{
//Wants to delete text
}

}];
return YES;
}

希望,能帮到你!

关于ios - 如何检测 UITextView 中的图像删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29571682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com