我最近使用自动参考计数(ARC)开始了一个新项目.
当我分配CALayer的内容时:
UIView* view = ...
UIImage* image = ...
view.layer.contents = image.CGImage
Run Code Online (Sandbox Code Playgroud)
我收到了一个错误
使用ARC不允许将非Objective-C指针类型'CGImageRef'隐式转换为'id'
简单地铸造CGImageRef到id隐藏的错误,但我想知道如果ARC仍然正常工作呢?
core-animation core-graphics objective-c ios automatic-ref-counting
我在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!) -> …Run Code Online (Sandbox Code Playgroud)