UIAatePicker在UIActionSheet分层问题中

jme*_*do3 6 iphone objective-c uidatepicker uialertview

有人在另一个问题中发布了这个代码,将UIDatePicker放在UIAlertSheet中:

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker" 
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];

// Add the picker
UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDate;
[menu addSubview:pickerView];
[menu showInView:self.view];        
[menu setBounds:CGRectMake(0,0,320, 500)];

CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = -100;
pickerView.bounds = pickerRect;

[pickerView release];
[menu release];
Run Code Online (Sandbox Code Playgroud)

我已将其修改为:

    UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:nil
                                                      delegate:nil
                                             cancelButtonTitle:@"Done"
                                        destructiveButtonTitle:nil
                                             otherButtonTitles:nil];

    // Add the picker
    UIDatePicker *pickerView = [[UIDatePicker alloc] init];
    pickerView.datePickerMode = UIDatePickerModeCountDownTimer;
    [menu addSubview:pickerView];
    [menu showInView:self.navigationController.tabBarController.view];        
    [menu setBounds:CGRectMake(0,0,320, 516)];
    [pickerView setFrame:CGRectMake(0, 85, 320, 216)];
Run Code Online (Sandbox Code Playgroud)

这会生成一个正确定位的警报表(忽略nil委托;这仅用于显示目的).问题在于:

alt text http://hosting-wizards.com/actionsheet.jpg

如您所见,在分钟滚动条上方,存在分层问题.我还没有确认是否在设备上发生这种情况.关于为什么会发生这种情况的任何想法?

另一个问题:为什么UIActionSheet上的setBounds选择器将Y-size设置为如此高的值以便正确显示?如果不是,将Y尺寸设置为480应创建全屏显示?将此值设置为零会使其几乎不可见.

侧面注意:上面粘贴的代码不会将UIDatePicker放置在图片中的相同位置,但无论UIDatePicker放在何处,都会出现分层问题.分层问题仅在顶部,而不在底部.

ben*_*ado 8

如果您只是将UIDatePicker放在新视图中并自己实现从下滑动的行为,您将避免显示问题并获得更好看的结果.这并不难.

  1. 创建一个包含日期选择器的UIView和一个带有Done按钮的工具栏.(在代码中或使用Interface Builder,无所谓.)
  2. 将弹出视图添加为主视图的子视图.
  3. 设置弹出视图的框架,使其不在屏幕底部: frame.origin.y = CGRectGetMaxY(mainView.bounds)
  4. 呼叫 [UIView beginAnimations:nil context:nil]
  5. 将框架设置为应该的位置: frame.origin.y -= CGRectGetHeight(popupView.bounds)
  6. 呼叫 [UIView commitAnimations]

(注意,帧设置的东西是伪代码.)

而已.当您需要关闭视图时,请反向执行.我认为值得麻烦; 在UIActionSheet中粘贴日期选择器看起来非常俗气.


Sim*_*ide 0

您可能会发现此线程对替代方法很有帮助:http://discussions.apple.com/message.jspa ?messageID=7923095