以模态方式呈现 UIDatePicker

发布于 2024-09-18 04:18:14 字数 239 浏览 2 评论 0原文

嘿,我有一个视图,其中有一个按钮,按下该按钮时应以模态方式呈现 UIDatePicker。我已经正确显示了选择器,但因为它位于其自己的 UIView 上,所以它是全高的,并且看起来很有趣。我想要的只是从用户那里获得真正快速的日期输入,更像是 UIActionSheet 而不是 UIView。

如何使 UIPicker 只向上滑动一半,并在工具栏上执行一些操作,例如完成等?

谢谢

Hey I have a view that has a button that when pressed should modally present a UIDatePicker. I have the picker showing up properly, but because it is on its own UIView, it is full height, and looks funny. All I want is to get a really quick date input from the user, more like a UIActionSheet than a UIView.

How can I make the UIPicker slide up modally only halfway and have some actions on a toolbar, like done etc?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花落人断肠 2024-09-25 04:18:14

您可以将其放在另一个具有透明背景的 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];
 }

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

You could put it on another UIView which has a transparent background, or more simply, don't use presentModalViewController, but write your own routine to show it in the current view.

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

You would of course need to add all the necessary code to keep a pointer to the picker and keep track of when to show and get rid of it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文