我正在创建一个以屏幕大小的 CGRect 开头的应用程序。当用户触摸 CGRect 内部时,它会被切割成两个 CGRect。当我触摸创建的新 CGRect 内部时,我让它工作得很好,但是当我触摸一个不是最新添加到 rectangleArray 的 CGRect 中时,应用程序崩溃并显示 sigabrt。
这里是touchesBegan中的代码,blockPoint是屏幕被触摸的点
for (NSValue *val in rectangleArray){
CGRect rectangle = [val CGRectValue];
if (CGRectContainsPoint(rectangle, blockPoint)) {
CGRect newRectangle;
CGRect addRectangle;
if (!inLandscape) {
newRectangle = CGRectMake(rectangle.origin.x, rectangle.origin.y, rectangle.size.width, blockPoint.y - rectangle.origin.y);
addRectangle = CGRectMake(rectangle.origin.x, blockPoint.y, rectangle.size.width, rectangle.size.height - (blockPoint.y - rectangle.origin.y));
}
else {
newRectangle = CGRectMake(rectangle.origin.x, rectangle.origin.y, blockPoint.x - rectangle.origin.x, rectangle.size.height);
addRectangle = CGRectMake(blockPoint.x, rectangle.origin.y, rectangle.size.width - (blockPoint.x - rectangle.origin.x), rectangle.size.height);
}
[rectangleArray replaceObjectAtIndex:[rectangleArray indexOfObject:val] withObject:[NSValue valueWithCGRect:newRectangle]];
[rectangleArray addObject:[NSValue valueWithCGRect:addRectangle]];
}
}
为什么会崩溃?