2011-08-18 210 views
1

因此,我打算做一个不同的方式来显示我的iPad应用程序中的历史记录,我认为用户可以从底部拉起历史视图,只要将UIView放置在那里并为它添加手势识别器?有没有“正确”的方式来做到这一点?我想让用户真正能够从底部拖动视图。如果你不明白,请提问,我会详细说明。从视图顶部呈现视图

回答

2

你有正确的想法。您将使用UIPanGestureRecognizer更新视图的frame。请记住,你必须有一些东西让用户随时“拉”可见 - 我认为你不能将视图完全隐藏在屏幕外。

像这样的事情会去的对象的实现您选择处理从手势识别事件(本示例假定它是你的视图控制器):

- (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

谢谢!我想我现在明白了。 –