嘿,我有一个视图,其中包含一个按钮,当按下时应该以模态方式呈现UIDatePicker
。 我已经成功地显示了选择器,但由于它在自己的UIView
上,因此它是全高度的,并且看起来很奇怪。 我想要的只是从用户那里获得一个非常快速的日期输入,更像是UIActionSheet
而不是UIView
。
我该如何使UIPicker
仅以模态方式滑动一半并在工具栏上执行一些操作,例如完成等?
谢谢
嘿,我有一个视图,其中包含一个按钮,当按下时应该以模态方式呈现UIDatePicker
。 我已经成功地显示了选择器,但由于它在自己的UIView
上,因此它是全高度的,并且看起来很奇怪。 我想要的只是从用户那里获得一个非常快速的日期输入,更像是UIActionSheet
而不是UIView
。
我该如何使UIPicker
仅以模态方式滑动一半并在工具栏上执行一些操作,例如完成等?
谢谢
// 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];
}
当然,您需要添加所有必要的代码来保持对选择器的指针,并跟踪何时显示和删除它。
CGRect *
类型。 - DanSkeel