在我的应用程序中,您可以触摸屏幕,屏幕上UITextField
会出现一个可编辑的内容。我希望能够UITextFields
在屏幕上移动这些新添加的内容。我还想添加一个旋转手势和一个捏合手势。现在这很难做到,因为每次点击屏幕都会添加一个新的 SubView ( UITextField
)。下面是我的编码:
- (IBAction)addText:(UITapGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateEnded)
{
UITextField *newText = [[UITextField alloc] initWithFrame:CGRectMake(40, 205, 280, 128)];
newText.hidden = NO;
[self.view addSubview:newText];
newText.text = @"phrase";
[newText setFont:[UIFont fontWithName:@"ArialRoundedMTBold" size:60]];
newText.borderStyle = UITextBorderStyleNone;
UIPanGestureRecognizer *pan= [[UIPanGestureRecognizer alloc] initWithTarget:newText action:nil];
CGPoint translation = [pan translationInView:newText];
pan.view.center = CGPointMake(pan.view.center.x + translation.x, pan.view.center.y + translation.y);
[pan setTranslation:CGPointMake(0,0) inView:self.view];
}
}