iPhone开发人员-绘图应用程序
首次用户和iPhone开发新手。我的问题集中在我的应用程序的架构上,而不是具体的代码。我的问题是:我是否走上了正确的道路,还是需要重新思考我对应用程序这一部分的处理方法 我正在尝试制作一个简单的“连接点”应用程序。我的应用程序有工作自由手绘触摸功能,我使用UIButtons来代表每个点 我通过调用2个UIButtons(点)的中心属性来解决这个问题,并设置条件,仅当开始/结束点是这2个点的中心坐标时,才绘制一条线。这不管用 所以我的问题是: UIButtons是表示每个点的最佳方法吗?如果是这样,每个点应该添加什么功能?它似乎是一个强有力的候选者,因为你可以调用中心属性并得到它的中心坐标。但由于我遇到了这个问题,我认为一个像素可能不够大,无法设置条件 如果UIButtons不是表示每个点的最佳方法,那么有什么更好的替代方法 最后,由于这个问题,我花了大量时间研究UIButtons的属性和功能。我无法通过UIButton找到对已发送事件选项描述的良好参考。有人知道一个好的博客/参考吗iPhone开发人员-绘图应用程序,iphone,objective-c,ipad,drawing,Iphone,Objective C,Ipad,Drawing,首次用户和iPhone开发新手。我的问题集中在我的应用程序的架构上,而不是具体的代码。我的问题是:我是否走上了正确的道路,还是需要重新思考我对应用程序这一部分的处理方法 我正在尝试制作一个简单的“连接点”应用程序。我的应用程序有工作自由手绘触摸功能,我使用UIButtons来代表每个点 我通过调用2个UIButtons(点)的中心属性来解决这个问题,并设置条件,仅当开始/结束点是这2个点的中心坐标时,才绘制一条线。这不管用 所以我的问题是: UIButtons是表示每个点的最佳方法吗?如果是这样
提前感谢您的帮助。ui不建议点击按钮。这里有一个示例供您通过触摸自由手绘
我不再关注
ui按钮及其事件,而是删除ui按钮
,重点关注触摸开始
、触摸移动
和触摸结束
方法。我合并了CGContext
方法,仅当UITouch
在特定初始位置和特定当前位置注册时才绘制线条。虽然我不确定这是否是解决我的问题的最理想/最有效的答案,但它运行良好,使我能够进入项目的下一阶段。如果任何人有改进此解决方案的建议,将不胜感激。下面是我用于此解决方案的代码片段:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if([touch tapCount] == 2) {
image1_.image = nil;
return;
}
initialPoint = [touch locationInView:self.view];
//If initial touch to screen is within 15 pixels of Dot 1, set coordinates to Dot 1
if(initialPoint.x > 36 && initialPoint.x < 66 && initialPoint.y > 161 && initialPoint.y < 191)
{
initialPoint.x = 51.0;
initialPoint.y = 176.0;
}
//If initial touch to screen is within 15 pixels of Dot 2, set coordinates to Dot 2
if(initialPoint.x > 199.5 && initialPoint.x < 229.5 && initialPoint.y > 170.5 && initialPoint.y < 190.5)
{
initialPoint.x = 214.5;
initialPoint.y = 175.5;
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];
//If current touch to screen is within 15 pixels of Dot 2, and the initial touch is
//set to Dot 1, draw line
if(currentPoint.x > 199.5 && currentPoint.x < 229.5 && currentPoint.y > 170.5 && currentPoint.y < 190.5 && initialPoint.x == 51.0 && initialPoint.y == 176.0)
{
currentPoint.x = 214.5;
currentPoint.y = 175.5;
UIGraphicsBeginImageContext(self.view.frame.size);
[image1_.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 4.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), initialPoint.x, initialPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
image1_.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lineIsDrawn = YES;
}
//If current touch to screen is within 15 pixels of Dot 3, and the initial touch is
//set to Dot 2, and a line has already been drawn between Dot 1 & Dot 2, draw line
if(currentPoint.x > 155.5 && currentPoint.x < 180.5 && currentPoint.y > 0 && currentPoint.y < 28.5 && initialPoint.x == 214.5 && initialPoint.y == 175.5 && lineIsDrawn == YES)
{
currentPoint.x = 170.5;
currentPoint.y = 13.5;
UIGraphicsBeginImageContext(self.view.frame.size);
[image1_.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 4.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), initialPoint.x, initialPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
image1_.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
UITouch*touch=[触摸任何对象];
如果([touch tapCount]==2){
image1_u2;image=nil;
返回;
}
initialPoint=[触摸位置视图:self.view];
//如果对屏幕的初始触摸在点1的15像素范围内,则将坐标设置为点1
if(initialPoint.x>36&&initialPoint.x<66&&initialPoint.y>161&&initialPoint.y<191)
{
初始点x=51.0;
初始点y=176.0;
}
//如果对屏幕的初始触摸在点2的15像素范围内,则将坐标设置为点2
如果(initialPoint.x>199.5&&initialPoint.x<229.5&&initialPoint.y>170.5&&initialPoint.y<190.5)
{
初始点x=214.5;
初始点y=175.5;
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch=[触摸任何对象];
currentPoint=[触摸位置视图:self.view];
//如果当前触摸屏在点2的15像素范围内,且初始触摸为
//设为点1,画线
如果(currentPoint.x>199.5&¤tPoint.x<229.5&¤tPoint.y>170.5&¤tPoint.y<190.5&&initialPoint.x==51.0&&initialPoint.y==176.0)
{
currentPoint.x=214.5;
电流点y=175.5;
UIGraphicsBeginImageContext(self.view.frame.size);
[image1_u2;.image drawInRect:CGRectMake(0,0,self.view.frame.size.width,
自身、视图、框架、尺寸、高度);
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),4.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0,0.0,0.0,1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(),initialPoint.x,initialPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
image1_u2;.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
lineIsDrawn=是;
}
//如果当前触摸屏在点3的15像素范围内,且初始触摸为
//设置为点2,并且点1和点2之间已经绘制了一条线,绘制线
如果(currentPoint.x>155.5&¤tPoint.x<180.5&¤tPoint.y>0&¤tPoint.y<28.5&&initialPoint.x==214.5&&initialPoint.y==175.5&&lineIsDrawn==YES)
{
currentPoint.x=170.5;
电流点y=13.5;
UIGraphicsBeginImageContext(self.view.frame.size);
[image1_u2;.image drawInRect:CGRectMake(0,0,self.view.frame.size.width,
自身、视图、框架、尺寸、高度);
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),4.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0,0.0,0.0,1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(),initialPoint.x,initialPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
image1_u2;.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
}
感谢您提供的链接,巧合的是,这就是我在应用程序中提到的示例。有人知道UIButton事件描述的博客/引用吗?