Ios Facebook类报纸的标题向上拖动,然后向下拖动,捕捉到屏幕底部

Ios Facebook类报纸的标题向上拖动,然后向下拖动,捕捉到屏幕底部,ios,objective-c,facebook,xcode5,Ios,Objective C,Facebook,Xcode5,我已经创建了一个类似于Facebook的纸质应用程序,我正试图弄清楚如何将视图拖到/抓拍到底部,然后再拖回。我很确定我已经完成了75%,但我一辈子都不知道该怎么把它搞定。 代码如下: - (IBAction)onDrag:(UIPanGestureRecognizer *)sender { CGPoint translation = [sender translationInView:self.view]; CGPoint center = self.headlinesView

我已经创建了一个类似于Facebook的纸质应用程序,我正试图弄清楚如何将视图拖到/抓拍到底部,然后再拖回。我很确定我已经完成了75%,但我一辈子都不知道该怎么把它搞定。 代码如下:

- (IBAction)onDrag:(UIPanGestureRecognizer *)sender {
    CGPoint translation = [sender translationInView:self.view];

    CGPoint center = self.headlinesView.center;

    // this is how high the tray should go
    int upperThreshold = self.view.frame.size.height - (self.headlinesView.frame.size.height / 2);
    // this is how low the tray should go
    int lowerThreshold = self.view.frame.size.height + (self.headlinesView.frame.size.height / 2);

    if (sender.state == UIGestureRecognizerStateBegan) {
        NSLog(@"start");
        // reset the tray location to where the tray currently is
        self.originalTrayLocation = self.headlinesView.center;
    } else if (sender.state == UIGestureRecognizerStateChanged) {
        NSLog(@"changed");

        if (center.y < upperThreshold) {
            // if the tray location is past the point where it should go,
            // add some resistance
            center.y = upperThreshold + (translation.y * 0.1);
        } else if (center.y > lowerThreshold) {
            // if the user drags down the tray a lot, don't make the tray
            // go that low
            center.y = lowerThreshold;
        } else {
            // drag as normal
            center.y = self.originalTrayLocation.y + translation.y;
        }
        self.headlinesView.center = center;
    } else if (sender.state == UIGestureRecognizerStateEnded) {
        NSLog(@"ended");
        // if the user dragged too far up or down, animate the tray
        // back to its desired location
        [UIView animateWithDuration:0.3 animations:^{
            self.headlinesView.center = CGPointMake(160, upperThreshold);
        }];
    }
}

有什么想法吗?

嗨,我也要这么做。你知道。。。。