开发者

Presenting a view by pulling from the top of the view

So I am planning to do a different way to display history in my iPad app and I think user could pull up the history view from the bottom, should I just place UIView there and add gesture recognizer for it? Is there any "right"开发者_开发百科 way to do this? I want to make the user actually able to drag the view from the bottom. If you don't understand, ask away and I will elaborate.


You have the right idea. You'd use a UIPanGestureRecognizer to update the view's frame. Keep in mind that you'll have to have something for the user to "pull" on visible at all times - I don't think you'll be able to hide the view completely off screen.

Something like this would go in the implementation of the object you choose to handle events from your gesture recognizer (this sample assumes it's your view controller):

- (void)handleDrag:(UIPanGestureRecognizer *)gesture {
    if (gesture.state == UIGestureRecognizerStateChanged ||
        gesture.state == UIGestureRecognizerStateEnded) {
        CGPoint translation = [gesture translationInView:self.view];
        CGRect newFrame = historyView.frame;
        newFrame.origin.x = newFrame.origin.x + translation.x;
        newFrame.origin.y = newFrame.origin.y + translation.y;
        historyView.frame = newFrame;

        // you need to reset this to zero each time
        // or the effect stacks and that's not what you want
        [gesture setTranslation:CGPointZero inView:self.view];
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜