简体   繁体   English

在文本视图中插入图像后,如何将光标下一行移动/跳转到图像视图

[英]How to move/jump the cursor next line to the image view after inserting image with in the text view

I have inserted an image from the library in the text view using the image picker, 我已使用图像选择器在文本视图中从库中插入了图像,

In pickeDelegate didFinishPickingImage method 在pickeDelegate didFinishPickingImage方法中

imgview = [[UIImageView alloc] initWithImage:image];

            NSString *messageText = [[NSString alloc]init];
            messageText = messageView.text;
            CGSize s = [messageText sizeWithFont:[UIFont systemFontOfSize:15] //define your textview font size
                               constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  //                                      lineBreakMode:UILineBreakModeWordWrap];   
            CGRect frame = CGRectMake(0.0f, s.height+10, 50, 50);//use YourImageView. height and width 
            imgview.frame=frame;

            //[imgview setFrame:CGRectMake(0, 0, 30,30) ];
            [messageView addSubview:imgview];

And implemented logic to add image at the end of the last text using followin delegate method logic 并实现了使用followin委托方法逻辑在最后文本末尾添加图像的逻辑

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
      if ( [text isEqualToString:@"\n"] ) {

      }
      else
      {
            NSString *yourstring = [[NSString alloc]init];
            yourstring = textView.text;
            CGSize s = [yourstring sizeWithFont:[UIFont systemFontOfSize:15] //define your textview font size
                              constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  // - 40 For cell padding
                                  lineBreakMode:UILineBreakModeWordWrap];   
            CGRect frame = CGRectMake(0.0f, s.height+10, 50, 50);//use YourImageView. height and width 
            imgview.frame=frame;
      }
      return YES;
}

but every time the cursor starts just before the image view, 但每次光标在即将开始的图像视图之前

But i need to jump/ move the cursor after the image when ever i added the image, jus like as folows, 但是i need to jump/ move the cursor after the image when ever i added the image, jus like as folows,

My requrement is user can type text in text view and he can add an image with in the text view then from the next line after image he can able to enter text again, 我的要求是,用户可以在文本视图中键入文本,并且可以在文本视图中添加, 然后从图像后的下一行开始再次输入文本,

just like we attach images in this stack over flow box like this 就像我们像这样在流框上将图像附加到该堆栈中一样

在此处输入图片说明

After insert image he could able to enter text again, 插入图片后,他可以再次输入文字,

how to do this any help.. thanks in advance 如何做到这一点任何帮助..在此先感谢

my previous question: Adding Images to UITextView 我之前的问题: 将图像添加到UITextView

如果要在插入图像后对文本字段做出响应,则-

    [YOURTEXTFIELD becomeFirstResponder];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM