gpt4 book ai didi

iphone - 以模态方式呈现 UIDatePicker

转载 作者:可可西里 更新时间:2023-11-01 04:42:54 24 4
gpt4 key购买 nike

嘿,我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com