iphone - 以模态方式呈现 UIDatePicker

标签 iphone uiviewcontroller ios uipickerview

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

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

谢谢

最佳答案

你可以将它放在另一个具有透明背景的 UIView 上,或者更简单地说,不要使用 presentModalViewController,而是编写你自己的例程以在当前 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];
 }

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

关于iphone - 以模态方式呈现 UIDatePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3655721/

相关文章:

ios - 是否有可能无法读取 UserDefaults.standard 值?

iphone - 如何释放 CGContextDrawPDFPage 创建的内存

ios - 来自 Xib 文件错误的 Swift init ViewController

uiviewcontroller - 是否可以在 UIViewController 的子类中实现 topLayoutGuide 和 bottomLayoutGuide?

iphone - -JSONValue 失败。错误是 : Unexpected end of input

objective-c - 如何保存在 UIWebview 控件中显示的 PDF(无需从网上重新加载)?

ios - ionic 4 : The "src" content of an "img" tag is not updating when I change it from the controller in IOS

iphone - 写信给 Pastie 或 Pastebin?

iphone - 从 iPhone 调用 Amazon S3 服务的安全性如何?

ios - 滑入/滑出 subview Controller 在 Swift 的父 View Controller 上部分可见