2012-07-17 4 views
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]; 
    } 
} 

답변

1

제스처 인식기 간의 종속성을 설정하는 몇 가지 방법이 있습니다. 여기서 유용한 방법은 requireGestureRecognizerToFail: 방법입니다. 당신이 pan 인식기를 만든 후,이 추가 : 팬 인식기는 사용자가 하지 패닝 것을 결정하지 않는 한

[recognizer requireGestureRecognizerToFail:pan]; 

지금합니다 ( recognizer 변수) 탭 인식기가 활성화되지 않습니다.

+0

현재 저는 UITapGestureRecognizer 하하를 방금 가져 왔습니다. UIBarButtonItem에서 UITextFields를 추가하기로 결정했습니다. 자, 내 모든 응용 프로그램 않는 UITextField 추가 할 수 있지만 화면 주위에 이동하려면 전체 UIView 주위에 이동합니다. –

관련 문제