您的位置:首页 > 产品设计 > UI/UE

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

2014-08-20 10:49 316 查看
/article/10430351.html

在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(@"线程未加载完成");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐