gpt4 book ai didi

iphone - UIImagePickerController 创建挂起几秒钟

转载 作者:行者123 更新时间:2023-12-03 21:10:04 26 4
gpt4 key购买 nike

我试图在 UIActionSheet 中单击按钮后显示 UIImagePickerController。代码很简单。但是,对 [[UIImagePickerController alloc] init] 的调用在完成之前会挂起几秒钟。我在模拟器中没有看到这种行为,但在 iPod 和 iPhone 上看到了。

以下是 UIActionSheetDelegate 方法。添加日志消息以显示执行时间。

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"Action sheet clicked button at index %d", buttonIndex);
switch (buttonIndex) {
case kSelectFromCameraButtonIndex:
[self showImagePickerWithCamera];
break;
case kSelectFromPhotoLibraryButtonIndex:
[self showImagePickerWithPhotoLibrary];
break;
}
}

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"Action sheet will dismiss with button index %d", buttonIndex);
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"Action sheet did dismiss with button index %d", buttonIndex);
}

这是实际创建 UIImagePickerController 的代码:

- (void)showImagePickerWithPhotoLibrary {
NSLog(@"Showing image picker with photo library");
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

NSLog(@"Creating picker");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];

NSLog(@"Setting picker settings");
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

NSLog(@"Presenting picker as modal view controller");
[self presentModalViewController:picker animated:YES];

NSLog(@"Releasing picker");
[picker release];
}
}

没什么特别的事情发生。但是,如果您查看控制台输出,您会注意到创建 UIImagePickerController 的行大约需要 7 秒才能完成。

2010-09-21 15:23:26.107 Oh Snap[1264:307] Action sheet clicked button at index 1
2010-09-21 15:23:26.113 Oh Snap[1264:307] Showing image picker with photo library
2010-09-21 15:23:26.120 Oh Snap[1264:307] Creating picker
2010-09-21 15:23:33.111 Oh Snap[1264:307] Setting picker settings
2010-09-21 15:23:33.123 Oh Snap[1264:307] Presenting picker as modal view controller
2010-09-21 15:23:33.136 Oh Snap[1264:307] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
2010-09-21 15:23:33.144 Oh Snap[1264:307] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate
2010-09-21 15:23:33.289 Oh Snap[1264:307] Releasing picker
2010-09-21 15:23:33.299 Oh Snap[1264:307] Action sheet will dismiss with button index 1
2010-09-21 15:23:33.916 Oh Snap[1264:307] Action sheet did dismiss with button index 1

有谁知道这是什么原因造成的吗?

最佳答案

我注意到在我的应用程序中 UIImagePickerController 需要很长时间才能创建。解决方法是在需要之前实例化它,即使在单独的线程上也是如此,然后在需要时呈现它。我猜想但无法确认这就是 Apple 使其速度相当快的方式。

关于iphone - UIImagePickerController 创建挂起几秒钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3764988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com