我在 WebView 上方放置了一个 UIView。在这个 UIView 中,我必须绘制,但应用程序因此错误而崩溃
在 LibraryViewController.m
self.drawView =[[DrawView alloc]init];
self.drawView.frame=CGRectMake(0, 0, 1024, 768);
self.drawView.backgroundColor=[UIColor redColor];
self.drawView.alpha=0.5;
[self.webView addSubview:self.drawView];
在 DrawView.h
#import <UIKit/UIKit.h>
@interface DrawView : UIView
@end
在 DrawView.m 中
@implementation DrawView
{
UIImage *incrementalImage;
//......
}
- (void)eraseDrawing:(UITapGestureRecognizer *)t
{
incrementalImage = nil;
[self setNeedsDisplay];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//.....
[incrementalImage drawAtPoint:CGPointZero];
[[UIColor blackColor] setStroke];
[[UIColor blackColor] setFill];
[offsetPath stroke]; // ................. (8)
[offsetPath fill];
incrementalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[offsetPath removeAllPoints];
dispatch_async(dispatch_get_main_queue(), ^{
bufIdx = 0;
[self setNeedsDisplay];
});
});
//.....
}
- (void)drawRect:(CGRect)rect
{
[incrementalImage drawInRect:rect]; //Thread 1:EXC_BAD_ACCESS (code=1 address=0xa000008)
}
此应用程序不使用 ARC