0
我有一個UIView從手勢識別器接收用戶平移。我意識到有些時候用戶會「拋出」我的觀點幾乎在屏幕之外,而且看起來很糟糕。我想防止這種情況發生。我知道我應該在選擇器中進行一些檢查,但是在翻譯視圖時我不知道該怎麼做。如何防止用戶平移我的視圖關閉屏幕?
這裏是我的代碼:
- (void)panPiece:(UIPanGestureRecognizer *)gestureRecognizer
{
UIView *piece = [gestureRecognizer view];
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
[piece setCenter:CGPointMake([piece center].x + translation.x, [piece center].y + translation.y)];
[gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
}
}
在此先感謝
問候
利奧