私のiPhoneプロジェクトの1つには、タッチしてドラッグすることで移動できる3つのビューがあります。ただし、2本の指を使用して、ユーザーが2つのビューを同時に移動できないようにします。そのため、UIView.exclusiveTouchを試してみましたが、成功しませんでした。
プロパティがどのように機能するかを理解するために、ViewControllerに次のコードを使用して新しいプロジェクトを作成しました。
- (void)loadView {
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
UIButton* a = [UIButton buttonWithType:UIButtonTypeInfoDark];
[a addTarget:self action:@selector(hej:) forControlEvents:UIControlEventTouchUpInside];
a.center = CGPointMake(50, 50);
a.multipleTouchEnabled = YES;
UIButton* b = [UIButton buttonWithType:UIButtonTypeInfoDark];
[b addTarget:self action:@selector(hej:) forControlEvents:UIControlEventTouchUpInside];
b.center = CGPointMake(200, 50);
b.multipleTouchEnabled = YES;
a.exclusiveTouch = YES;
[self.view addSubview:a];
[self.view addSubview:b];
}
- (void)hej:(id)sender
{
NSLog(@"hej: %@", sender);
}
これを実行すると、いずれかのボタンを押すと、異なる送信者でhej:が呼び出されます。ただし、ボタンの1つでexclusiveTouchがYESに設定されている場合でも同様です。私はmultipleTouchEnabled-linesにコメントを付けようとしましたが、役に立ちませんでした。誰かが私がここで欠けているものを私に説明できますか?
ありがとう、エリ