【问题标题】:How to move/jump the cursor next line to the image view after inserting image with in the text view在文本视图中插入图像后如何将光标下一行移动/跳转到图像视图
【发布时间】:2012-11-07 08:14:08
【问题描述】:

我使用图像选择器在文本视图中插入了库中的图像,

在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];

并使用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;
}

但每次光标在图像视图之前开始时,

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

我的要求是用户可以在文本视图中输入文本,他可以在文本视图中添加图像然后从图像的下一行他可以再次输入文本,

就像我们在这个堆栈中附加图像,像这样

插入图片后可以再次输入文字,

如何做到这一点任何帮助..提前谢谢

我之前的问题:Adding Images to UITextView

【问题讨论】:

    标签: iphone objective-c ipad uiimageview uitextview


    【解决方案1】:

    如果您想在插入图片后回复您的文本字段,那么-

        [YOURTEXTFIELD becomeFirstResponder];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多