【发布时间】:2013-09-30 10:01:27
【问题描述】:
我在 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
【问题讨论】:
-
你似乎在
drawRect的外部绘图? -
当我在 UIView 上移动手指时必须进行绘制
-
然后你使视图无效以强制重绘,你不只是开始绘图。见
[UIView setNeedsDisplay]。 -
incrementalImage是什么类型的?它在哪里实例化?你期望在这里发生什么?你所做的只是强制一些其他对象(可能也是 UIView 子类?)来绘制自己,你可能会强制它进入一个可能不是它自己的绘图区域的矩形。 -
那里有
[incrementalImage drawAtPoint:CGPointZero];是否正确?它甚至有意义吗?
标签: ios objective-c uiview compiler-errors exc-bad-access