ユーザーがビュー内のどこをタップしたかを認識し、その場所に UITextField を作成できる iPad アプリを作成しています。これをプログラムする最も効率的な方法は何ですか? 複数のテキスト フィールドで機能しますか?
質問する
78 次
3 に答える
1
UIに関する限り、あなたのアイデアは少し不安定に聞こえると思いますが、おそらくUITapGestureRecognizer
. コードは次のようになります。
// In viewDidLoad
UITapGestureRecognizer *tapRecognizer = [UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedInView:)];
[self.view addGestureRecognizer:tapRecognizer];
- (void)tappedInView:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint pointForTextField = [gestureRecognizer locationInView:gestureRecognizer.view];
// Add the UITextField to your view. You could use the pointForTextField as either the origin or center of the text field
UITextField *textField = [UITextField alloc] initWithFrame:CGRectMake(pointForTextField.x,pointForTextField.y,100,44)];
[self.view addSubview:textField];
}
于 2012-10-31T05:53:27.903 に答える
0
これを行う:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint locationPoint = [[touches anyObject] locationInView:self.view];
if(locationPoint)
{
//add UITextField
yourTextField.frame = CGRectMake(locationPoint.x, locationPoint.y, 40,40); //change height and width according
}
}
于 2012-10-31T06:03:35.717 に答える
0
//text field move where you touch in screen
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *myTouch = [touches anyObject];
point = [myTouch locationInView:self.view];
NSLog(@"%f,%f",point.x, point.y);
yourTextField.frame = CGRectMake(point.x, point.y, width,height);
}
于 2012-10-31T06:02:36.040 に答える