使用:要するにDrag a UIView part-way, then it moves on its own設定位置の制限この質問は、私が最近作っこの投稿への何らかの関係があるUIPanGestureRecognizer
は、私は、ウィンドウの下部の一部が見えるドラッグ可能なUIビューを持っています。ユーザーが画面上のビューを上または下にドラッグするために使用できる「プルタブ」があります。
- (void)panPiece:(UIPanGestureRecognizer *)gestureRecognizer
{
UIView *piece = [gestureRecognizer view];
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged)
{
CGPoint velocity = [gestureRecognizer velocityInView:[piece superview]];
CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
if(velocity.y < 0) //user is dragging the view upwards the screen
{
// Set the maximum Ypos as the top 1/3rd of the screen
CGFloat maxYPos = self.view.frame.size.height/3;
if(blogTextView.frame.origin.y >= maxYPos)
{
[piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
}
else
{
// User is dragging the view downwards the screen
// Set the lowest Y position to be 420
if(blogTextView.frame.origin.y <= 420) //size of remaining view
{
[piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
}
}
}
私は、これは醜いと思う:これはそれを行うための正しい方法がある場合、私はこのコードを使用して上下位置のためのY位置に制限を置いてきたが、私は見当もつかないただし、ユーザーがビューをゆっくりドラッグしている場合は機能します。問題は、ユーザーが画面を非常に急速に画面の上または下にドラッグすると、ビューをY位置に置いた制限を超えて引っ張ることができるということです。たとえば、ドラッグ可能なビューを下にしたデフォルトの状態では、スナップのような速度でビューをナビゲーションバーにドラッグすることができました。
ビューをドラッグできる距離の制限を設定する正しい方法があり、このgestureRecognizerコールバックで正しく処理されますか?
は参考のため、ここでのテストアプリの写真です:
Default screen with draggable view at the bottom and the pull tab
View dragged up to its correct max Y position
ありがとうございます!
if(blogTextView.frame.origin.y >= maxYPos)
{
[piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
そして、この1:
if(blogTextView.frame.origin.y <= 420) //size of remaining view
{
[piece setCenter:CGPointMake([piece center].x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
があなた、あなたが実行された場合、あなたが得るでしょうblogTextView.frame.origin.y
(値の将来値を使用する必要があります
** blogTextView **と** piece **は何ですか? – sch