【问题标题】:crash at drawInRect:rect, I've the solution but don't know how?在drawInRect:rect崩溃,我有解决方案但不知道如何?
【发布时间】:2011-07-21 11:46:06
【问题描述】:

该应用程序在 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();

}

提前一百万谢谢...

【问题讨论】:

  • 你能提供崩溃日志吗,它会帮助你解决问题。

标签: iphone objective-c cocoa-touch crash drawrect


【解决方案1】:

您没有说崩溃的确切位置,但您已经使用UIGraphicsBeginImageContext 创建了一个图像上下文,然后使用CGBitmapContextCreate 创建了另一个图像上下文。我的猜测是后一个问题是问题(让论点正确可能很棘手),而且无论如何都不是你想要的。所以改成:

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

【讨论】:

  • Hi Dark,之前是这样的 CGContextRef context = UIGraphicsGetCurrentContext();然后我在您看到新行时对其进行了更改,但同样它不起作用....崩溃发生在以下行:[ucdView.image drawInRect:rect];任何帮助将不胜感激...
  • 抱歉,由于您没有提供崩溃日志和/或确切的错误消息,恐怕我现在无法提供帮助。我不知道为什么它会在那条线上崩溃。
猜你喜欢
  • 1970-01-01
  • 2020-06-10
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
  • 1970-01-01
  • 2023-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多