以模态方式呈现UIDatePicker

时间:2010-09-07 04:14:04

标签: iphone uiviewcontroller ios uipickerview

嘿,我有一个视图,其中有一个按钮,按下时应按模式显示UIDatePicker。我有正确显示的选择器,但因为它是自己的UIView,它是全高,看起来很有趣。我想要的只是从用户那里得到一个非常快速的日期输入,更像是UIActionSheet而不是UIView

如何让UIPicker只在模板上滑动一半并在工具栏上执行某些操作,比如完成等等?

由于

1 个答案:

答案 0 :(得分:4)

你可以将它放在另一个具有透明背景的UIView上,或者更简单地说,不要使用presentModalViewController,而是编写自己的例程以在当前视图中显示它。

 // Untested code:
 // put this in your current UIViewController (the one where you were going to call presentModalViewController:)

 - (void)showPicker:(UIPickerView *) picker{
      CGRect startFrame = picker.frame;
      CGRect endFrame = picker.frame;
      // Set the start position to below the bottom of the visible frame:
      startFrame.origin.y = self.view.frame.size.height;
      // Set the end position to slid up by the height of the view, so it will just fit:
      endFrame.origin.y = startFrame.origin.y - endFrame.size.height;    
      picker.frame = startFrame;

      [self.view addSubView:picker];
      [UIView beginAnimations]
      picker.frame = endFrame;
      [UIView commitAnimations];
 }

你当然需要添加所有必要的代码来保持指向选择器的指针,并跟踪何时展示和摆脱它。