【问题标题】:Presenting a UIDatePicker modally以模态方式呈现 UIDatePicker
【发布时间】:2011-04-09 00:23:05
【问题描述】:

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

我怎样才能让UIPicker 模态地向上滑动一半,并在工具栏上执行一些操作,例如完成等?

谢谢

【问题讨论】:

    标签: iphone uiviewcontroller ios uipickerview


    【解决方案1】:

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

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

    【讨论】:

    • 完美!这正是我所需要的
    • 没有beginAnimations方法。而且你不能使用CGRect * 类型。
    猜你喜欢
    • 1970-01-01
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    相关资源
    最近更新 更多