iphone - 在drawInRect:rect崩溃,我有解决方案,但不知道如何?

标签 iphone objective-c cocoa-touch crash drawrect

该应用程序可以在iphone模拟器上正常运行,但是当我们在实际的iphone设备上运行它时,它在以下行崩溃:

[ucdView.image drawInRect:rect];

我已经搜索并找到了解决方案,但是我不知道如何解决,因为我们在这个星期五不得不提出该问题的时间很短。查看以下解决方案:
Must drawInRect: for a separate context be executed on the main thread?

发生崩溃的部分在viewDidLoad()中的Sculpture.m中
- (void)viewDidLoad{
[super viewDidLoad]; 

CLController = [[CoreLocationController alloc] init];
CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];

currentLoc = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"redPin.png"]];

UIImage *ucdImage = [UIImage imageNamed:@"ucd.png"];
self.ucdView = [[UIImageView alloc] initWithImage:ucdImage];//creating a view for UCD image
ucdView.userInteractionEnabled = YES;

[self loadingFile];

UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[myScrollView setMinimumZoomScale:0.35];
[myScrollView setMaximumZoomScale:2.0];
myScrollView.clipsToBounds = YES;
myScrollView.bounces = YES;
myScrollView.contentOffset = CGPointMake(1400, 700);
[myScrollView setContentSize:CGSizeMake(ucdImage.size.width, ucdImage.size.height)];
[myScrollView setDelegate:self];
[myScrollView addSubview:ucdView];//adding ucd view to scroll view
[self.view addSubview:myScrollView]; // adding scrollview to self.view main view
[myScrollView release];


//Drawing The Line
UIGraphicsBeginImageContext(ucdView.frame.size);
CGRect rect = CGRectMake(0, 0, ucdView.frame.size.width, ucdView.frame.size.height);
[ucdView.image drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 3.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGFloat dashArray[] = {2,0,2,2};
CGContextSetLineDash(context, 3, dashArray, 5);
CGContextMoveToPoint(context,[self longt_to_x:[[path_array objectAtIndex:0] doubleValue]],[self lat_to_y:[[path_array objectAtIndex:1] doubleValue]]);
int path_length = [path_array count];
for(int i = 2; i<path_length; i = i+2){
    CGContextAddLineToPoint(context,[self longt_to_x:[[path_array objectAtIndex:i] doubleValue]],[self lat_to_y:[[path_array objectAtIndex:i+1] doubleValue]]);
}
CGContextStrokePath(context);
ucdView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

}

预先感谢一百万...

最佳答案

您没有说明崩溃的确切位置,但是您已经使用UIGraphicsBeginImageContext创建了一个图像上下文,然后使用CGBitmapContextCreate创建了另一个图像上下文。我的猜测是,下一个问题是问题(正确设置参数可能很棘手),而且无论如何都不是您想要的。因此将其更改为:

// Get the current drawing context which is the image context right now
CGContextRef context = UIGraphicsGetCurrentContext();

关于iphone - 在drawInRect:rect崩溃,我有解决方案,但不知道如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6775485/

相关文章:

iphone - iPhone 的录音格式?

iphone - 如何像sqlite一样将整数值保存到NSuserDefault?

ios - 使用 dequeueReusableCellWithIdentifier 时保留单元格之间的单元格属性

objective-c - iPad 键盘方向错误

iphone - 如何在 iPhone 中创建短信应用程序

objective-c - NSDictionary 过滤和排序

ios - 如何覆盖导航栏

ios - 在 iOS 中将 XML 转换为 JSON

ios - 在 iOS 上解析 NSURL 路径和查询

iphone - iOS 中的色轮或颜色选择器