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放在何处,都会出现分层问题.分层问题仅在顶部,而不在底部.
如果您只是将UIDatePicker放在新视图中并自己实现从下滑动的行为,您将避免显示问题并获得更好看的结果.这并不难.
frame.origin.y = CGRectGetMaxY(mainView.bounds)[UIView beginAnimations:nil context:nil]frame.origin.y -= CGRectGetHeight(popupView.bounds)[UIView commitAnimations](注意,帧设置的东西是伪代码.)
而已.当您需要关闭视图时,请反向执行.我认为值得麻烦; 在UIActionSheet中粘贴日期选择器看起来非常俗气.