设想:
UIScrollView 有一个 UIButton。点击 UIButton 会导致 UIPopoverController 从指定的矩形呈现自己。UIPopoverController 的 contentViewController 是一个带有 UIDatePicker 的 UIViewController。
点击按钮时触发的代码(按钮是自定义类型,在点击内注册了修饰):
- (void)showCalendar:(id)sender {
dateViewController = [[UIViewController alloc] init];
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 240, 200)];
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.hidden = NO;
datePicker.date = [NSDate date];
[datePicker addTarget:self
action:@selector(DateChanged:)
forControlEvents:UIControlEventValueChanged];
NSLocale *US = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setLocale:US];
[datePicker setCalendar:cal];
[datePicker setMaximumDate:[NSDate date]];
dateViewController.view = datePicker;
dateViewController.contentSizeForViewInPopover = CGSizeMake(240, 200);
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:dateViewController];
self.popoverController.delegate = self;
NSLog(@"YESYESYES");
[self.popoverController presentPopoverFromRect:CGRectMake(753, 513, 1, 1) inView:parentView permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
NSLog(@"NONONO");
}
当我将设备连接到 Xcode 并运行应用程序时,两个 NSLog 语句之间存在明显的 1 秒或更长时间的延迟。这种滞后的原因可能是什么?