我如何在视图屏幕周围拖动UITextView? [英] How would I drag UITextView around the view screen?

查看:73
本文介绍了我如何在视图屏幕周围拖动UITextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,可以在屏幕上拖动UITextView(用于多行).到目前为止,我对此的解决方案是覆盖不可见的UIButton,将其拖动时其中心与UITextView的中心相同.

I have a project where a UITextView (for multilines) can be dragged around the screen. So far my solution to this has been an overlay of an invisible UIButton which when dragged its center is the same as the UITextView's center.

但是,我见过一些似乎只允许UITextView即时进行拖动和编辑的应用程序,因此似乎这些应用程序中可能没有覆盖层,但我不确定.

However I've seen apps that seem to just allow the UITextView to be dragged and edited on the fly so it seems there might not be an overlay in those but I'm not sure.

有想法吗?

顺便说一句,这段代码中的c是UIButton,这就是到目前为止我将其移动的方式:

By the way, c in this code is the UIButton and this is how I have moved it thus far:

- (void) draggedOut: (UIControl *) c withEvent: (UIEvent *) ev 
{

 if(self.interfaceOrientation == UIInterfaceOrientationPortrait)
 {
  c.center = [[[ev allTouches] anyObject] locationInView:self.view];
  AddedText.center = c.center;
 }
 else if(self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
 {
  c.center = [[[ev allTouches] anyObject] locationInView:self.view];
  AddedText.center = c.center;
 }
 else if(self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
 {
  c.center = [[[ev allTouches] anyObject] locationInView:self.view];
  AddedText.center = c.center;
 }
 else if(self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
 {
  c.center = [[[ev allTouches] anyObject] locationInView:self.view];
  AddedText.center = c.center;
 }
}

推荐答案

- (void)panTextView:(UIPanGestureRecognizer *)recognizer {
      NSLog(@"panning");

 location1 = [recognizer translationInView:draggableTextView];


    recognizer.view.center = CGPointMake(recognizer.view.center.x + location1.x,
                                    recognizer.view.center.y + location1.y);



        [recognizer setTranslation:CGPointMake(0,0) inView:draggableTextView];

     location1 =[recognizer locationInView:draggableTextView];
       NSLog(@"tranlation %@",NSStringFromCGPoint(location1));

     [_imgpic addSubview:recognizer.view];

 appDelegate.txt=draggableTextView.text;
}

在创建textview后调用此方法.

call this method after creating textview.

这篇关于我如何在视图屏幕周围拖动UITextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆