尽管我认为我的定位正确,但我的 UIDatePicker 的一部分从屏幕底部延伸出来。有人可以告诉我我做错了什么吗?我已经经历了以下几行,但无法弄清楚我哪里出错了。我试图避免为我的 UIDatePicker 框架明确指定坐标。我在这里包含了我的视图控制器中的相关代码:
// Create the time picker
self.timePicker = [[UIDatePicker alloc] init];
[self.timePicker addTarget:self action:@selector(datePickerDateChanged:) forControlEvents:UIControlEventValueChanged];
self.timePicker.datePickerMode = UIDatePickerModeTime;
// Set the time picker frame
CGRect screenRect = [self.view frame];
CGSize pickerSize = [self.timePicker sizeThatFits:CGSizeZero];
CGRect pickerRect = CGRectMake(screenRect.origin.x,
screenRect.origin.y + screenRect.size.height - pickerSize.height,
pickerSize.width,
pickerSize.height);
NSLog(@"Picker frame: %f", screenRect.size.height);
NSLog(@"Picker frame: %f", screenRect.origin.y + screenRect.size.height - pickerSize.height);
[self.timePicker setFrame:pickerRect];
// Add the picker to the view
[self.view addSubview:self.timePicker];