加载UIImagePickerController更快? [英] Load UIImagePickerController faster?

本文介绍了加载UIImagePickerController更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更快地加载UIImagePickerController.我的应用程序可能会从多个控制器中调用UIImagePickerController,并且在每个控制器中有两个按钮,一个用于照片库,另一个用于照相机.这是我的示例应用程序.苹果在"并发编程指南"中推荐了我尝试过的某些解决方案.
最简单的方法是分配&当用户按下按钮时初始化一个实例.最多可能需要2秒钟才能显示相机.解决方案尝试:-
(1)我制作了一个@property(...)* imagePicker,并将其称为alloc&. viewDidAppear中的init使其看起来很平滑,但是它干扰了其他元素的加载,可能是因为它使用的是同一线程.在initWithNibNameviewDidLoad中使用时,结果更差.
(2)Operation queues ...不令人满意的结果.
(3)Dispatch Queues ...更好的结果,但仍表现出断断续续的表现.
(4)performSelectorInBackground:withObject:效果不佳.除非另有建议,否则我不认为我想走出去.我没有问题,使两个UIImagePickerController的@properties.我将继续阅读"线程编程指南".
如果可以的话,请在解决方案中包括所有必要的内存管理实践.谢谢.

I need to load UIImagePickerController faster. My app will call UIImagePickerController from possibly multiple controllers and within each controller there are two buttons, one for Photo Library, another for Camera. This is my sample app. Some solutions I tried are recommended by Apple in 'Concurrency Programming Guide'.
The simplest is to alloc & init an instance when user presses a button. This can take up to 2 seconds before the camera shows up.
Solution attempt:-
(1) I made a @property (...) *imagePicker and called its alloc & init in viewDidAppear to make it seem smooth, but it interfered with loading of other elements, possibly because it was using the same thread. Worse results when used in initWithNibName or viewDidLoad.
(2) Operation queues... not pleasing results.
(3) Dispatch Queues... better results but still noticeable choppy performance.
(4) performSelectorInBackground:withObject: not great results. I don't think I want to go global, unless otherwise recommended. I have no problem making two @properties of UIImagePickerController. I will continue to possibly 'Threading Programming Guide'.
Please include any necessary memory management practices with your solutions, if you can. Thank you.

- (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在评论中的答案:

from @Murat's answer in a comment:

我找到了解决方案.这个问题已经回答.它 似乎当连接到Xcode调试器时,[UIImagePickerController alloc] init]的执行时间比运行该应用程序时要长得多 没有Xcode.

I found the solution. This question has already been answered. It seems when connected to Xcode debugger the [UIImagePickerController alloc] init] takes much longer to execute than when running the App without Xcode.

我的解决方案仍然是保留@property并执行alloc & initviewDidLoad方法中.

My solution is still to keep @property and do the alloc & init in the viewDidLoad method.

另一个解决方案在这里: UIViewController-神秘地加载缓慢

The other solution is here: UIViewController - mysteriously slow to load

将其移至答案,因为我差点错过它作为评论.

moved this to an answer as I almost missed it as a comment.

这篇关于加载UIImagePickerController更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆