我编写了代码以在UIview
(TestView)中添加imageview。在触摸委托方法中添加图像我点按视图中的任意位置然后将图像添加到UIview
(testview)并且这个图像也被添加到一个可变数组中,该数组在appdelegate类中声明。
另一个数组包含该图像的框架。
上面的过程是为每个点击添加图像。
在删除过程中,我们删除了可变数组的图像和相关索引。
我们还可以将任何图像移动到视图中的任何位置。
但是构建工作非常慢并且在ipad设备上运行并显示以下错误: -
Program received signal: “0”. Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point_Temp = [[[event allTouches] anyObject] locationInView:TestView];
point_TouchStart = [[[event allTouches] anyObject] locationInView:TestView];
bool_ValidtouchFound = NO;
for(int int_Temp=0; int_Temp < [appDelegate_iPad.marry_ContainsRect count]; int_Temp+=1)
{
NSValue *val_Temp = [appDelegate_iPad.marry_ContainsRect objectAtIndex:int_Temp];
CGRect rect_Temp = [val_Temp CGRectValue];
NSLog(@"rect_Temp = %f, %f",rect_Temp.origin.x,rect_Temp.origin.y);
if(CGRectContainsPoint(rect_Temp, point_Temp))
{
bool_ValidtouchFound = YES;
int_TextIndex = int_Temp;
imgview_Temp = [appDelegate_iPad.marry_ContainsImages objectAtIndex:int_TextIndex];
for(UIImageView *imgview_Transparent in [imgview_Temp subviews])
imgview_Dummy = imgview_Transparent;
[imgview_Dummy setFrame:CGRectMake(0.0, 0.0, imgview_Temp.frame.size.width, imgview_Temp.frame.size.height)];
[imgview_Dummy setBackgroundColor:[UIColor clearColor]];
[imgview_Temp addSubview:imgview_Dummy];
if([appDelegate_iPad.marry_ContainsImages count] > int_Temp)
imgview_Text = [appDelegate_iPad.marry_ContainsImages objectAtIndex:int_Temp];
break;
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if(bool_IsTextReadyToMove
&& ![appDelegate_iPad.CurrentFeatureStatus isEqualToString:@"Pencil"]
&& ![appDelegate_iPad.CurrentFeatureStatus isEqualToString:@"Eraser"]
&& ![appDelegate_iPad.CurrentFeatureStatus isEqualToString:@"Brush"])
{
float float_difx = [[touches anyObject] locationInView:imgview_Text].x - [[touches anyObject] previousLocationInView:imgview_Text].x;
float float_dify = [[touches anyObject] locationInView:imgview_Text].y - [[touches anyObject] previousLocationInView:imgview_Text].y;
CGAffineTransform transform_NewTemp = CGAffineTransformTranslate(imgview_Text.transform, float_difx, float_dify);
imgview_Text.transform = transform_NewTemp;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(bool_ValidtouchFound)
{
if(appDelegate_iPad.bool_IsTextReadyToDraw)// code to draw images
{
UIImage *img_Temp = [UIImage imageNamed:appDelegate_iPad.str_ImageName];
UIImageView *imgview_DrawText = [[UIImageView alloc]initWithImage:img_Temp ];
CGRect rect_Temp = CGRectMake(point_Temp.x, point_Temp.y, img_Temp.size.width, img_Temp.size.height);
[imgview_DrawText setFrame:rect_Temp];
[imgview_DrawText setTag:101];
UIImageView *imgview_SubView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0, 0.0, img_Temp.size.width, img_Temp.size.height)];
[imgview_SubView setBackgroundColor:[UIColor clearColor]];
[imgview_DrawText addSubview:imgview_SubView];
// [imgview_SubView sendSubviewToBack:imgview_DrawText];
// [imgview_DrawText bringSubviewToFront:imgview_SubView];
// imgview_DrawText.layer.borderColor = [[UIColor blackColor] CGColor];
// imgview_DrawText.layer.borderWidth =0.6f;
[appDelegate_iPad.marry_ContainsRect addObject:[NSValue valueWithCGRect:rect_Temp]];
[appDelegate_iPad.marry_ContainsImages addObject:imgview_DrawText];
[TestView addSubview:imgview_DrawText];
if(imgview_DrawText)
{
[imgview_DrawText release];
imgview_DrawText = nil;
}
if(imgview_SubView)
{
[imgview_SubView release];
imgview_SubView = nil;
}
if(img_Temp)
img_Temp = nil;
NSLog(@"Array Count After Addition = %d",[appDelegate_iPad.marry_ContainsRect count]);
}
else // Code for Delete images
{
for(int int_Temp=0; int_Temp < [appDelegate_iPad.marry_ContainsRect count]; int_Temp+=1)
{
NSValue *val_Temp = [appDelegate_iPad.marry_ContainsRect objectAtIndex:int_Temp];
CGRect rect_Temp = [val_Temp CGRectValue];
if(CGRectContainsPoint(rect_Temp, point_Temp))
{
UIImageView *imgview_RemoveText = [appDelegate_iPad.marry_ContainsImages objectAtIndex:int_Temp];
[imgview_RemoveText removeFromSuperview];
imgview_RemoveText = nil;
[appDelegate_iPad.marry_ContainsRect removeObjectAtIndex:int_Temp];
[appDelegate_iPad.marry_ContainsImages removeObjectAtIndex:int_Temp];
break;
}
}
NSLog(@"Array Count After Deletion = %d",[appDelegate_iPad.marry_ContainsRect count]);
}
}
}
所以,请给我帮助。 感谢