Note that there are some explanatory texts on larger screens.

plurals
  1. POUITextView strange behavior
    primarykey
    data
    text
    <p>Okay I'm lost here.</p> <p>So have this <code>UIViewController</code> we can call it <code>viewController1</code> where I add a new editable <code>UITextView</code> for every click on an add button.</p> <p>I then use <code>UIPanGestureRecognizer</code> so you can drag them where ever you want. This works just fine. Now I want to go to <code>viewController2</code>: <code>[self.navigationController pushViewController:viewController2 animated:YES];</code> but when I press the back button to return to <code>viewController1</code> the first <code>UITextView</code> that was created in <code>viewController1</code> has changed. It's not gone but the text property inside the textview has moved. </p> <p><strong>This just happens for the first instance of UITextView</strong> that I create, any ideas here would be appreciated. Here's my method for creating the text:</p> <pre><code>-(void)addTextFieldToScreen { UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(10, 80, 140, 120)]; textView.text = @"TEXT"; textView.backgroundColor = [UIColor clearColor]; textView.textColor = [UIColor purpleColor]; textView.font = [UIFont fontWithName:@"AmericanTypewriter" size:30]; textView.userInteractionEnabled = YES; UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveText:)]; panRecognizer.minimumNumberOfTouches = 1; panRecognizer.maximumNumberOfTouches = 1; panRecognizer.delegate = self; [textView addGestureRecognizer:panRecognizer]; [self.view addSubview:textView]; } </code></pre> <p>And here's my method for making my textView dragable:</p> <pre><code>-(void)moveText:(id)sender { [[[(UITapGestureRecognizer*)sender view] layer] removeAllAnimations]; [self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]]; CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view]; if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) { firstX = [[sender view] center].x; firstY = [[sender view] center].y; } translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y); [[sender view] setCenter:translatedPoint]; if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { CGFloat finalX = translatedPoint.x + (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].x); CGFloat finalY = translatedPoint.y + (.35*[(UIPanGestureRecognizer*)sender velocityInView:self.view].y); CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat workingWidth = screenRect.size.width - 40; CGFloat workingHeight = screenRect.size.height - 80; if(finalX &lt; 50) { finalX = 50; } else if(finalX &gt; workingWidth ) { finalX = workingWidth; } if(finalY &lt; 80) { finalY = 80; } else if(finalY &gt; workingHeight) { finalY = workingHeight; } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDuration:.20]; [UIView commitAnimations]; } } </code></pre> <p><strong>EDIT:</strong></p> <p>Okay here's whats going on, I add two textviews with content "TEXT" with the "add text" button in the right corner in viewController1:</p> <p><img src="https://i.stack.imgur.com/7kmVP.png" alt="enter image description here"></p> <p>And then when I come back from viewController2 to viewController1 this is what I see:</p> <p><img src="https://i.stack.imgur.com/5t5sa.png" alt="enter image description here"></p> <p>As you can see it's only the left textView instance text property that change position, and this is the first one I'm adding.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload