使用线程加载UIImagePickerController,解决卡屏问题

在iphone真机上利用主线程调用照片库或是照相机一般会很卡,开一个独立线程单独加载会给用户节约时间

以下是我的想法,直接上代码:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    //线程加载imgpicker
    thread = [[NSThread alloc] initWithTarget:self selector:@selector(initImgPicker) object:nil];
    [thread start];
}

-(void)initImgPicker
{
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    if (imagePickerController==nil) {
        imagePickerController = [[JCImagePickerController alloc] init];
        imagePickerController.delegate = self;
    }
    [pool release];
}


#pragma mark 控制选项
-(IBAction)getPhotoFromPicker:(id)sender
{
        //判断机器是否有camera
        if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
           //
        }else {
            if ([thread isFinished]) {
                imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
                [self presentModalViewController:imagePickerController animated:YES];
            }
            else {
                NSLog(@"线程未加载完成");
            }


}


版权声明:本文为Arrui原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。