以模态方式呈现UIDatePicker

5

嘿,我有一个视图,其中包含一个按钮,当按下时应该以模态方式呈现UIDatePicker。 我已经成功地显示了选择器,但由于它在自己的UIView上,因此它是全高度的,并且看起来很奇怪。 我想要的只是从用户那里获得一个非常快速的日期输入,更像是UIActionSheet而不是UIView

我该如何使UIPicker仅以模态方式滑动一半并在工具栏上执行一些操作,例如完成等?

谢谢

1个回答

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];
 }

当然,您需要添加所有必要的代码来保持对选择器的指针,并跟踪何时显示和删除它。


1
完美!这正是我需要的。 - Jerry
没有beginAnimations方法。而且你不能使用CGRect *类型。 - DanSkeel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接