0
我想實現類似Mac/iOS網頁如何實現的地方,如果你拉過一定的門檻,主視圖變得「有彈性」,並基於拉力的速度。使UIPanGestureRecognizer伸展時拉過一定的門檻
不同的是,我試圖用UIPanGestureRecognizer爲UITableViewCells水平執行此操作。
我有一個handlePan
方法:
- (void)handlePan:(UIPanGestureRecognizer *)recognizer
{
[recognizer setMaximumNumberOfTouches:1];
CGPoint velocity = [recognizer velocityInView:self];
int panDelta = ([recognizer locationInView:self].x - [recognizer locationInView:self.superview].x);
if (recognizer.state == UIGestureRecognizerStateBegan) {
_originalCenter = self.center;
}
if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:self];
float xVal = 0;
if (panDelta <= 38) {
xVal = _originalCenter.x + translation.x;
} /*else {
// this is where I struggle.
xVal = _originalCenter.x;
}*/
self.center = CGPointMake(xVal, _originalCenter.y);
}
if (recognizer.state == UIGestureRecognizerStateEnded) {
CGRect newFrame;
int xOffset = 0;
newFrame = CGRectMake(xOffset, self.frame.origin.y,
self.bounds.size.width, self.bounds.size.height);
[UIView animateWithDuration:0.2 animations:^{
self.frame = newFrame;
}];
}
}
我沒有任何具體的算法創建了「拉伸性」;我所要做的就是讓滑動不會像用戶的交互一樣廣泛,並且流暢。
想法?