2011-08-18 209 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

謝謝!我想我現在明白了。 –