http://blog.csdn.net/arrui/article/details/6318640
在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(@"线程未加载完成");
}
}