使用 UIDatePickerMode.DateAndTime 时 UIDatePicker 中断
我正在使用 Monotouch 5 创建一个应用程序,并且在 iPad 模拟器中运行我的应用程序时,在 iOS 4.3 或更低版本上创建模式为 UIDatePickerMode.DateAndTime 的日期选择器时遇到问题。尽管我为其框架和周围视图设置的尺寸非常好,但 DatePicker 总是损坏。
这是在装有 iOS 4.3 的 iPad 模拟器上的样子:
http://screencast.com/t/isIRcUcKCF5< /a>
这是它在 iOS 5.0 的 iPad 模拟器上的样子:
http://screencast.com/t/UxPTpR0Btzb
在 iPhone 模拟器或真实设备上不会出现此问题。我知道在装有 iOS 5 的真实 iPad 设备上也不会发生这种情况,但我无法测试 4.3 或更低版本,因为我没有这样的设备。
创建日期选择器的源代码如下:
public override void Selected (MonoTouch.Dialog.DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
var vc = new MyViewController (this) {
Autorotate = dvc.Autorotate
};
datePicker = CreatePicker ();
datePicker.Frame = PickerFrameWithSize (datePicker.SizeThatFits (SizeF.Empty));
//vc.View encompasses the entire, screen so there is plenty of space available for the date picker
vc.View.BackgroundColor = UIColor.Black;
vc.View.AddSubview (datePicker);
dvc.ActivateController (vc);
}
public virtual UIDatePicker CreatePicker ()
{
var picker = new UIDatePicker (RectangleF.Empty){
AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
Mode = UIDatePickerMode.DateAndTime,
Date = DateValue,
};
return picker;
}
static RectangleF PickerFrameWithSize (SizeF size)
{
var screenRect = UIScreen.MainScreen.ApplicationFrame;
float fY = 0, fX = 0;
switch (UIApplication.SharedApplication.StatusBarOrientation){
case UIInterfaceOrientation.LandscapeLeft:
case UIInterfaceOrientation.LandscapeRight:
fX = (screenRect.Height - size.Width) /2;
fY = (screenRect.Width - size.Height) / 2 -17;
break;
case UIInterfaceOrientation.Portrait:
case UIInterfaceOrientation.PortraitUpsideDown:
fX = (screenRect.Width - size.Width) / 2;
fY = (screenRect.Height - size.Height) / 2 - 25;
break;
}
// calculated values:
// fx: 224
// fy: 369
// size.Width: 320
// size.Height: 320
return new RectangleF (fX, fY, size.Width, size.Height);
}
当我使用模式为 UIDatePickerMode.Date 或 UIDatePickerMode.Time 的日期选择器时,不会出现该问题。
该问题看起来就像 iPad 上的空白 UIDatePicker 模式 UIDatePickerModeDateAndTime,但是由于某些奇怪的原因,那里描述的修复在我的情况下不起作用。
任何有关如何解决此错误的提示将不胜感激。
谢谢,
阿德里安
I'm creating an app with Monotouch 5 and I'm having a problem with creating a datepicker with the mode UIDatePickerMode.DateAndTime on iOS 4.3 or lower when running my app in an iPad Simulator. The DatePicker is always broken, although the dimensions I set for it's frame and the surrounding view are perfectly fine.
This is how it looks like on an iPad Simulator with iOS 4.3:
http://screencast.com/t/isIRcUcKCF5
and this is how it looks on an iPad Simulator with iOS 5.0:
http://screencast.com/t/UxPTpR0Btzb
This problem does not occur on iPhone Simulators or real devices. I know it also does not occur on real iPad devices with iOS 5, but I could not test 4.3 or lower because I have no such device.
The source code for creating the date picker is as follows:
public override void Selected (MonoTouch.Dialog.DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
var vc = new MyViewController (this) {
Autorotate = dvc.Autorotate
};
datePicker = CreatePicker ();
datePicker.Frame = PickerFrameWithSize (datePicker.SizeThatFits (SizeF.Empty));
//vc.View encompasses the entire, screen so there is plenty of space available for the date picker
vc.View.BackgroundColor = UIColor.Black;
vc.View.AddSubview (datePicker);
dvc.ActivateController (vc);
}
public virtual UIDatePicker CreatePicker ()
{
var picker = new UIDatePicker (RectangleF.Empty){
AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
Mode = UIDatePickerMode.DateAndTime,
Date = DateValue,
};
return picker;
}
static RectangleF PickerFrameWithSize (SizeF size)
{
var screenRect = UIScreen.MainScreen.ApplicationFrame;
float fY = 0, fX = 0;
switch (UIApplication.SharedApplication.StatusBarOrientation){
case UIInterfaceOrientation.LandscapeLeft:
case UIInterfaceOrientation.LandscapeRight:
fX = (screenRect.Height - size.Width) /2;
fY = (screenRect.Width - size.Height) / 2 -17;
break;
case UIInterfaceOrientation.Portrait:
case UIInterfaceOrientation.PortraitUpsideDown:
fX = (screenRect.Width - size.Width) / 2;
fY = (screenRect.Height - size.Height) / 2 - 25;
break;
}
// calculated values:
// fx: 224
// fy: 369
// size.Width: 320
// size.Height: 320
return new RectangleF (fX, fY, size.Width, size.Height);
}
When I am using a datepicker with the modes UIDatePickerMode.Date or UIDatePickerMode.Time, the problem does not occur.
The problem looks just like blank UIDatePicker on iPad in mode UIDatePickerModeDateAndTime, but the fix described there does not work in my case for some weird reason.
Any hints on how to work around this bug would be greatly appreciated.
Thanks,
Adrian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我仍然不知道如何使上面的代码工作,但我设法通过使用 UIPopupView 来显示日历来解决这个 iOS 错误。
I still don't have a clue how to make the code above work, but I managed to work around this iOS bug by using a UIPopupView for displaying the calendar instead.