配列内の各UIViewにUIPanGestureRecognizerを割り当てることで、この問題を「解決」しました。
これはおそらく最善の方法ではありませんが、画面上で移動できるようになりました。
コードは次のとおりです。
for (int x = 0; x < [keys count]; x++) {
UIPanGestureRecognizer *pGr = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dragging:)];
UIView *sca = [self.studentCellArray objectAtIndex:x];
[sca addGestureRecognizer:pGr];
[pGr release];
}
これが私が使用した「ドラッグ」方法です。画面を3分の1に分割しましたが、しきい値を超えた場合にUIViewをポイントにスナップするアニメーションがあります。これが誰かに良いアイデアを与えることを願っています。これを行うためのより良い方法が見つかれば、助けてください。
- (void) dragging:(UIPanGestureRecognizer *)p{
UIView *v = p.view;
if (p.state == UIGestureRecognizerStateBegan || p.state == UIGestureRecognizerStateChanged) {
CGPoint delta = [p translationInView:studentListScrollView];
CGPoint c = v.center;
c.x += delta.x;
//c.y += delta.x;
v.center = c;
[p setTranslation:CGPointZero inView:studentListScrollView];
}
if (p.state == UIGestureRecognizerStateEnded) {
CGPoint pcenter = v.center;
//CGRect frame = v.frame;
CGRect scrollFrame = studentListScrollView.frame;
CGFloat third = scrollFrame.size.width/3.0;
if (pcenter.x < third) {
pcenter = CGPointMake(third/2.0, pcenter.y);
//pop the view
[self showModalDialog:YES perfMode:YES andControlTag:[studentCellArray indexOfObjectIdenticalTo:p.view]];
}
else if (pcenter.x >= third && pcenter.x < 2.0*third) {
pcenter = CGPointMake(3.0*third/2.0, pcenter.y);
}
else
{
pcenter = CGPointMake(5.0 * third/2.0, pcenter.y);
//pop the view
[self showModalDialog:YES perfMode:YES andControlTag:[studentCellArray indexOfObjectIdenticalTo:p.view]];
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
v.center = pcenter;
[UIView commitAnimations];
}
}
編集:andControlTagに[studentCellArray indexOfObjectIdenticalTo:p.view]を追加すると、タッチしたビューの配列内の位置がわかり、モーダルダイアログでそれを渡して適切な情報を表示できます。