加载UIImagePickerController更快?

我需要加载UIImagePickerController更快。 我的应用程序将从可能的多个控制器调用UIImagePickerController ,并在每个控制器中有两个button,一个用于照片库,另一个用于相机。 这是我的示例应用程序。 我尝试过的一些解决scheme是Apple在“ 并发编程指南 ”中推荐的。
最简单的是当用户按下button时,分配&init实例。 相机出现之前最多可能需要2秒钟的时间。
解决scheme尝试: –
(1)我做了一个@property(…)* imagePicker,并在viewDidAppear调用它的alloc&init来使它看起来很stream畅,但是它妨碍了加载其他元素,可能是因为它使用了同一个线程。 在initWithNibNameviewDidLoad使用时会导致较差的结果。
(2) Operation queues …不令人满意的结果。
(3) Dispatch Queues …更好的结果,但仍然明显的波涛汹涌的performance。
(4) performSelectorInBackground:withObject:不是很好的结果。 除非另有build议,否则我不认为我想走向世界。 我没有任何问题,使两个@properties的UIImagePickerController 。 我将继续可能的' 线程编程指南 '。
如果可以的话,请在您的解决scheme中包含任何必要的内存pipe理实践。 谢谢。

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // (1) TRYING OPERATION QUEUES // (a) --- NSBlockOperation NSBlockOperation *NSBO_IP = [NSBlockOperation blockOperationWithBlock:^{ NSLog(@"before"); imagePicker = [[UIImagePickerController alloc] init]; // 1.9, 1.6, 1.4 seconds pass between 'before' and 'after' // it seems this method has a dynamic technique, executes in different order every time NSLog(@"after"); }]; // (b) --- NSInvocationOperation NSInvocationOperation *NSIO_IP = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadTheImagePicker) object:nil]; // --- Add an operation NSOperationQueue *queue = [[NSOperationQueue alloc] init]; //NSLog(@"time 1"); // (a) [queue addOperation:NSBO_IP]; // (b) [queue addOperation:NSIO_IP]; //NSLog(@"time 2"); // (2)TRYING DISPATCH QUEUES // (a) --- GCD call (do I need to release 'myQueue' at some point since this is C-level call?) /* NSLog(@"time 1"); dispatch_queue_t myQueue = dispatch_queue_create("My Queue", NULL); dispatch_async(myQueue, ^{ imagePicker = [[UIImagePickerController alloc] init]; // 1.2, 1.2, 1.2, 1.4 seconds significant increase over Operation Queues // a solid constant executing technique, executes very consistently }); NSLog(@"time 2"); */ // (3)TRYING performSelectorInBackground:withObject (not recommended?) NSLog(@"time 1"); [self performSelectorInBackground:@selector(loadTheImagePicker) withObject:nil]; // 1.3, 1.7, 1.3 seconds pass between 'before' and 'after' NSLog(@"time 2"); // RESULTS REFLECTED IN LINE BELOW ! [self changeText:self]; // text does not change on time when trying to alloc & init an ImagePickerController } - (void)loadTheImagePicker { NSLog(@"before"); imagePicker = [[UIImagePickerController alloc] init]; // --- NSInvocationOperation used // 1.6, 1.2, 1.4 seconds pass between 'before' and 'after' // this method has a more constant executing technique, as far as order of executions // --- NSInvocationOperation used NSLog(@"after"); } 

来自@ Murat在评论中的回答:

我find了解决scheme。 这个问题已经被回答了。 看起来当连接到Xcodedebugging器时, [UIImagePickerController alloc] init]比在没有Xcode的情况下运行App要花费更多时间。

我的解决scheme仍然保持@property ,并在viewDidLoad方法中执行allocinit

另一个解决scheme是在这里: UIViewController – 神秘缓慢加载

提出这个答案,因为我几乎错过了它作为一个评论。