ユーザーが定規を動かしてUITableViewをスクロールできるようにするアプリケーションに取り組んでいます。現時点では、UITableView の行のみに移動を制限したいことを除いて、ルーラーは問題なく移動します。残念ながら、現時点では、ユーザーはテーブル全体を上からスクロールして、テーブルの下部を超えて画面の下部までスクロールできます。これを示すために画像を添付しました:
私が持っている関連コードは次のとおりです。
- (void)panGestureDetected:(UIPanGestureRecognizer *)recognizer {
CGPoint newCenter = _imageView.center;
newCenter.y = [recognizer locationInView:[_imageView superview]].y;
if (newCenter.y - _imageView.frame.size.height / 2 < self.table.frame.origin.y)
newCenter.y = self.table.frame.origin.y + _imageView.frame.size.height / 2;
else if (newCenter.y + _imageView.frame.size.height / 2 > self.table.frame.origin.y + self.table.frame.size.height)
newCenter.y = self.table.frame.origin.y + self.table.frame.size.height - _imageView.frame.size.height / 2;
_imageView.center = newCenter;
if ([recognizer state] == UIGestureRecognizerStateChanged) {
if (newCenter.y == self.table.frame.origin.y + _imageView.frame.size.height / 2) {
CGPoint topPoint = [recognizer locationInView:_table];
NSIndexPath *nextRow = [_table indexPathForRowAtPoint:topPoint];
int currentRow = nextRow.row;
if (currentRow != 0) {
nextRow = [NSIndexPath indexPathForRow:currentRow-- inSection:0];
[UIView animateWithDuration:.3 animations:^{
[_table selectRowAtIndexPath:nextRow animated:NO scrollPosition:UITableViewScrollPositionBottom];
}];
}
}
//below is the specific section where I believe is the issue
else if (newCenter.y == self.table.frame.origin.y + self.table.frame.size.height - _imageView.frame.size.height / 2) {
CGPoint bottomPoint = [recognizer locationInView:_table];
NSIndexPath *nextRow = [_table indexPathForRowAtPoint:bottomPoint];
int currentRow = nextRow.row;
if (currentRow != [self.tireCode count]-1) {
nextRow = [NSIndexPath indexPathForRow:currentRow++ inSection:0];
[UIView animateWithDuration:.3 animations:^{
[_table selectRowAtIndexPath:nextRow animated:NO scrollPosition:UITableViewScrollPositionBottom];
}];
}
}
}
私が言ったように、ルーラーは UITableView の行だけをスクロールし、それ以上はスクロールしないようにしたいと思います。私が間違っているのは何ですか?