Shy*_*wal 5 memory-leaks uiimagepickercontroller ios swift
我在swift中遇到了UIImagePickerController的一个严重问题.在连续捕获50-60张图像后,应用程序崩溃而没有在结构崩溃中记录任何问题.这似乎是一个记忆问题.我尝试了以下解决方案.
@interface UIImagePickerController (Singleton)
+(UIImagePickerController *) instance;
@end
@implementation UIImagePickerController (Singleton)
+(UIImagePickerController *) instance{
static UIImagePickerController *_instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken,^{
_instance=[[UIImagePickerController alloc] init];
});
return _instance
}
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
let image = UIImagePickerController.instance() //Singleton call used here
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.Camera
image.allowEditing = true
self.presentViewController(image,animated: true,completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){
autoreleasepool{
var image: UIImage? =info[UIImagePickerControllerOriginalImage] as! UIImage
imageView.image = Utils.resizeAndCompress(image)
image=nil
}
self.dismissViewControllerAnimated(true,completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
知道这里有什么问题吗?我们将不胜感激.谢谢
class func resizeAndCompress(image: UIImage!) -> UIImage? {
let size = image.size
let maxLength: CGFloat = 640.0
var newSize: CGSize
if size.width > size.height {
let scale = maxLength / size.width
newSize = CGSizeMake(maxLength, size.height * scale)
} else {
let scale = maxLength / size.height
newSize = CGSizeMake(size.width * scale, maxLength)
}
// This is the rect that we've calculated out and this is what is actually used below
let rect = CGRectMake(0, 0, newSize.width, newSize.height)
// Actually do the resizing to the rect using the ImageContext stuff
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
image.drawInRect(rect)
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return resizedImage
}
Run Code Online (Sandbox Code Playgroud)
崩溃的解决方案 问题出现在iOS版本中.我使用AVVideoCapture创建了自定义图像选择器控件.现在我能够拍摄超过1000张图像.
| 归档时间: |
|
| 查看次数: |
476 次 |
| 最近记录: |