私はオブジェクティブ C のプログラミング学習の初心者であり、このサイトでの質問の初心者でもありますが、ご容赦ください。
現在、画面上にボックス (UIControls) の列を描画し、それらを上下に無限にスクロールできるようにしようとしています。そのため、画面の下部から外れると、下部に移動して再利用されます。
コードに多くの間違いがあるに違いないことはわかっています。しかし、私がやろうとしていることの要点は次のとおりです。ボックスはすべて配列(imArray)にあります。ボックスが画面の下部からスクロールすると、配列の最後から取り除かれ、最初に挿入されます。次に、ボックスがグラフィカルに列の上部に挿入されます。
最初の if ステートメントは、画面の下部からのスクロールを処理し、正常に動作します。しかし、同様のコードで反対のことをしようとする 2 番目の if ステートメントは、ゆっくりとスクロールする場合にのみ機能します。すばやくスクロールすると、ボックス間の間隔が不均一になり、ボックスが画面上でロックされて動かなくなることがあります。
任意の助けをいただければ幸いです。必要な場合は、さらに明確にするよう努めます。
-(BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint pt = [touch locationInView:self];
int yTouchEnd = pt.y;
int yTouchChange = yTouchEnd - yTouchStart;
//iterate through all boxes in imArray
for(int i = 0; i < self.numberOfSections; i++)
{
//1. get box
STTimeMarker *label = self.imArray[i];
//2. calculate new label transform
label.transform = CGAffineTransformTranslate(label.startTransform, 0, yTouchChange);
CGRect frame = label.frame;
//3. if the box goes out of the screen on the bottom
if (frame.origin.y > [[UIScreen mainScreen]bounds].size.height)
{
//1. move box that left the screen to to beginning of array
[self.imArray removeObjectAtIndex:i];
[self.imArray insertObject:label atIndex:0];
//2. get y value of box closest to top of screen.
STTimeMarker *labelTwo = self.imArray[1];
CGRect frameTwo =labelTwo.frame;
//3. put box that just left the screen in front of the box I just got y value of.
frame.origin.y = frameTwo.origin.y - self.container.bounds.size.height/self.numberOfSections;
label.frame=frame;
}
//1. if the box goes out of the frame on the top
// (box is 40 pixels tall)
if (frame.origin.y < -40)
{
[self.imArray removeObjectAtIndex:i];
[self.imArray addObject:label];
STTimeMarker *labelTwo = self.imArray[self.numberOfSections-1];
CGRect frameTwo =labelTwo.frame;
frame.origin.y = frameTwo.origin.y + self.container.bounds.size.height/self.numberOfSections;
label.frame=frame;
}
}
return YES;
}