使用线程加载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(@"线程未加载完成");
}
}
在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(@"线程未加载完成");
}
}
相关文章推荐
- 使用线程加载UIImagePickerController,解决卡屏问题
- 使用UIImagePickerController时3DTouch引起的Crash问题的解决--备用
- 使用UIImagePickerController时3DTouch引起的Crash问题的解决
- iOS开发中使用相机或系统相册的一些问题总结(UIImagePickerController)
- iOS App内存优化之 解决UIImagePickerController的图片对象占用RAM过高问题
- iOS开发-使用UIImagePickerController遇到的问题
- 使用UIImagePickerController拍照或者视频选择问题
- 使用安装在linux端的loadgenerator,在controller加载并发人数受限的问题解决
- 使用UIImagePickerController拍照或者视频选择问题
- 在使用UIImagePickerViewcontroller的时候,状态栏的颜色会被改变的解决办法
- 调用系统UIImagePickerController录像并保存到指定的文件夹,解决保存后播放视频角度偏移90度问题
- 使用安装在linux端的loadgenerator,在controller加载并发人数受限的问题解决
- 使用安装在linux端的loadgenerator,在controller加载并发人数受限的问题解决
- 解决Swift中present(uiImagePickerController,animated: true,completion: nil)闪退的问题
- 使用安装在linux端的loadgenerator,在controller加载并发人数受限的问题解决
- IOS-解决自定义UIImagePickerController 后的图片翻转问题
- 关于将系统自带的UIImagePickerController 作为uitabbarcontroller时 present时出现问题的解决
- 解决当把系统自带的UIImagePickerController 作为一个uiviewcontroller时有20像素间隙的问题
- Android使用BitmapFactory.Options解决加载大图片内存溢出问题
- 解决在log4net 中使用sqlite 无法加载“SQLite.Interop.066.DLL ”的问题