使用了下面报错Passed-by-value struct argument contains uninitialized data (e.g., via the field chain: 'origin.x')
- (instancetype)init
{
if (self = [super init]) {
CGRect viewSize;
viewSize.size.width = viewSize.size.height = layerViewWH;
self.frame = viewSize;
self.backgroundColor = [UIColor clearColor];
}
return self;
}
改成下面就好了
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:CGRectMake(0, 0, layerViewWH, layerViewWH)]) {
self.backgroundColor = [UIColor clearColor];
}
return self;
}
//后来知道了CGRect使用之前记得初始化,应该这样使用
- (instancetype)init
{
if (self = [super init]) {
CGRect viewSize = CGRectZero;
viewSize.size.width = viewSize.size.height = layerViewWH;
self.frame = viewSize;
self.backgroundColor = [UIColor clearColor];
}
return self;
}
2.使用且图片的时候,造成的内存泄露
UIImage *image = [UIImage imageNamed:@"AppIcon"];
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], viewSize);
UIImage *imageS = [UIImage imageWithCGImage:imageRef];
加上这句就好了 CGImageRelease(imageRef);