0
내 앱에서 화면을 터치하면 편집 가능한 UITextField
이 화면에 표시됩니다. 나는 이것들을 화면 주위에 새롭게 추가 된 UITextFields
으로 옮길 수 있기를 원한다. 또한 회전 동작과 집어 넣기 동작을 추가하고 싶습니다. 화면을 누를 때마다 새 하위보기 (UITextField
)가 추가되기 때문에 지금 당장 실행하기가 어렵습니다. 아래 코드는 다음과 같습니다.프로그래밍 방식으로 UIPanGestureRecognizer를 추가하는 방법
- (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];
}
}
현재 저는 UITapGestureRecognizer 하하를 방금 가져 왔습니다. UIBarButtonItem에서 UITextFields를 추가하기로 결정했습니다. 자, 내 모든 응용 프로그램 않는 UITextField 추가 할 수 있지만 화면 주위에 이동하려면 전체 UIView 주위에 이동합니다. –