底部弹出UIPicker?

发布于 2024-09-13 08:34:34 字数 92 浏览 7 评论 0原文

调用action时从屏幕底部弹出的UIPicker是否只是一个以某种方式协调的基本UIPickerView? (就像 UIActionSheet 一样?)我将如何实现它?

Is the UIPicker that pops up from the bottom of the screen when an action is called just a basic UIPickerView that is coordinated in a certain way? (Like a UIActionSheet?) How would I implement that?

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

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

发布评论

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

评论(4

热情消退 2024-09-20 08:34:34

这是我使用的动画代码:

- (void)animateDatePicker:(BOOL)show {
    CGRect screenRect = self.frame;
    CGSize pickerSize = [self.datePickerView sizeThatFits:CGSizeZero];
    CGRect startRect = CGRectMake(0.0,
                                  screenRect.origin.y + screenRect.size.height,
                                  pickerSize.width, pickerSize.height);

    CGRect pickerRect = CGRectMake(0.0,
                                   screenRect.origin.y + screenRect.size.height - pickerSize.height,
                                   pickerSize.width,
                                   pickerSize.height);

    self.datePickerView.frame = pickerRect;
    self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.7f - (int)show * 0.7f );

    if ( show ) {
        self.datePickerView.frame = startRect;
        [self.parentViewController addSubviewToWindow:self];
    }

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationDelegate:self];

    self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.0f + (int)show * 0.7f );

    if ( show ) {
        self.datePickerView.frame = pickerRect;
    } else {
        [UIView setAnimationDidStopSelector:@selector(slideDownDidStop)];
        self.datePickerView.frame = startRect;
    }

    [UIView commitAnimations];  
}

datePickerView 是一个视图,其中包含 DatePicker:

self.datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 174.0, 320.0, 286.0)];
self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 70.0, 320.0, 216.0)];
[self.datePicker setDatePickerMode:UIDatePickerModeDate];
[self.datePicker addTarget:self action:@selector(pickerValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.datePickerView addSubview:self.datePicker];

parentViewController 应该实现 addSubviewToWindow 方法:

- (void)addSubviewToWindow:(UIView *)addView {
    [self.view addSubview:addView];
}

UIColorMakeRGBA:

#define UIColorMakeRGBA(nRed, nGreen, nBlue, nAlpha) [UIColor colorWithRed:(nRed)/255.0f green:(nGreen)/255.0f blue:(nBlue)/255.0f alpha:nAlpha]

slideDownDidStop 是一个方法,在 datePicker 成功向下滑动后将调用该方法。

所以,总结一下 - 你有 MyViewController,它有

MyDatePickerView *myDatePicker;

字段。

MyDatePickerView 是一个自定义类,具有 UIDatePicker *datePicker 字段、MyViewController *parentViewController 和 animateDatePicker 方法。

当您在 MyViewController 上执行某些操作(例如,对某些按钮执行 UIControlEventTouchUpInside)时,您应该调用“

[myDatePicker animateDatePicker:YES];

如果您有疑问,请告诉我”。

更新:
这是一个小示例

Here's animation code, that I use:

- (void)animateDatePicker:(BOOL)show {
    CGRect screenRect = self.frame;
    CGSize pickerSize = [self.datePickerView sizeThatFits:CGSizeZero];
    CGRect startRect = CGRectMake(0.0,
                                  screenRect.origin.y + screenRect.size.height,
                                  pickerSize.width, pickerSize.height);

    CGRect pickerRect = CGRectMake(0.0,
                                   screenRect.origin.y + screenRect.size.height - pickerSize.height,
                                   pickerSize.width,
                                   pickerSize.height);

    self.datePickerView.frame = pickerRect;
    self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.7f - (int)show * 0.7f );

    if ( show ) {
        self.datePickerView.frame = startRect;
        [self.parentViewController addSubviewToWindow:self];
    }

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3f];
    [UIView setAnimationDelegate:self];

    self.backgroundColor = UIColorMakeRGBA( 64, 64, 64, 0.0f + (int)show * 0.7f );

    if ( show ) {
        self.datePickerView.frame = pickerRect;
    } else {
        [UIView setAnimationDidStopSelector:@selector(slideDownDidStop)];
        self.datePickerView.frame = startRect;
    }

    [UIView commitAnimations];  
}

datePickerView is a view, that contains DatePicker:

self.datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 174.0, 320.0, 286.0)];
self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 70.0, 320.0, 216.0)];
[self.datePicker setDatePickerMode:UIDatePickerModeDate];
[self.datePicker addTarget:self action:@selector(pickerValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.datePickerView addSubview:self.datePicker];

parentViewController should implement addSubviewToWindow method:

- (void)addSubviewToWindow:(UIView *)addView {
    [self.view addSubview:addView];
}

UIColorMakeRGBA:

#define UIColorMakeRGBA(nRed, nGreen, nBlue, nAlpha) [UIColor colorWithRed:(nRed)/255.0f green:(nGreen)/255.0f blue:(nBlue)/255.0f alpha:nAlpha]

slideDownDidStop is a method, that will be called after datePicker slide down successfully.

So, just to summarize - you have MyViewController, that have

MyDatePickerView *myDatePicker;

field.

MyDatePickerView is a custom class, that have UIDatePicker *datePicker field, MyViewController *parentViewController and animateDatePicker method.

When you perform some action on MyViewController (for example, UIControlEventTouchUpInside for some button), you should invoke

[myDatePicker animateDatePicker:YES];

Please let me know if you have questions.

UPDATE:
Here's a small example.

对你再特殊 2024-09-20 08:34:34

将 UIPickerView 放入新的 UIViewController 类中(我们称之为 PopupUIPicker),然后通过以下方式显示该视图控制器:

PopupUIPicker *pickerController = [[[PopupUIPicker alloc] init] autorelease];
[currentViewController presentModalViewController:pickerController animated:YES];

其中 currentViewController 是要在其上显示它的视图控制器。关闭它:

[currentViewController dismissModalViewControllerAnimated:YES];

默认动画是从底部向上滑动。您可以将其更改为:

pickerController.modalTransitionStyle = UIModalTransitionStylePartialCurl;

Put a UIPickerView in a new UIViewController class (let's call it PopupUIPicker) and then display that View Controller via:

PopupUIPicker *pickerController = [[[PopupUIPicker alloc] init] autorelease];
[currentViewController presentModalViewController:pickerController animated:YES];

Where currentViewController is the View Controller you want to display it on. To dismiss it:

[currentViewController dismissModalViewControllerAnimated:YES];

The default animation is to slide up from the bottom. You can change it like:

pickerController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
千里故人稀 2024-09-20 08:34:34

“调用操作时从屏幕底部弹出的 UIPicker”是什么意思?

如果您想大致了解 Facebook 应用程序的功能,请查找 Three20,这是他们的开源 UI库(不能保证他们使用的组件在那里;我没有检查过)。

What do you mean by "the UIPicker that pops up from the bottom of the screen when an action is called"?

If you want to do roughly what the Facebook app does, look up Three20 which is their open-source UI library (no guarantee that the component they use is there; I haven't checked).

鲜血染红嫁衣 2024-09-20 08:34:34

我和 Rob 有同样的问题...我可以弹出 UIPicker...但它填满整个屏幕...我只想弹出选择器...Matt 说你不必制作视图占据整个框架...调整视图大小不起作用...如何使选择器弹出?我仍然可以看到父视图的一部分...就像 iphone 上的 safari 处理下拉菜单一样。

I have the same issue as as Rob... I can make the UIPicker popup... but it fills the whole screen... i want just the picker to popup... Matt says you don't have to make the view take up the entire frame ... resizing the view along does not work... How do you make just the picker pop up? i was to still see the part of the parent view... much like safari on iphone handles dropdowns.

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