1

对于我正在使用的所有人

 UITapGestureRecognizer*singleTap = [[[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(doSingleTap:)] autorelease];
    singleTap.numberOfTouchesRequired = 2;
    [self.view addGestureRecognizer:singleTap

接触

在 doSingleTap: 方法中我有这个

-(void)doSingleTap:(UITapGestureRecognizer *)recognizer
{
    CGPoint point = [recognizer locationOfTouch:0 inView:self.view];
    NSLog(@"location X =>%f,location  =>%f ",point.x,point.y);
    CGPoint point1 = [recognizer locationOfTouch:1 inView:self.view];
    NSLog(@"location X =>%f,location  =>%f ",point1.x,point1.y);

     NSLog(@"location X =>%f,location  =>%f ",x,y);
    UIView *test1 = [[UIView alloc]initWithFrame:CGRectMake(point.x, point1.y, x, y)];
    test1.backgroundColor= [UIColor greenColor];
    [self.view addSubview:test1];


}

根据手指位置或位置视图在主视图上添加新视图时遇到问题,根据位置视图正确添加视图。

我希望根据两个手指添加该视图并自动调整它们的(x,y,w,h)。如果有人帮助我,我需要帮助在此先感谢我在谷歌上搜索但没有得到任何帮助

4

3 回答 3

1
float x = (point.x < point1.x) ? point.x : point1.x;
float y = (point.y < point1.y) ? point.y : point1.y;
float width = fabsf(point.x - point1.x);
float height = fabsf(point.y - point1.y);
UIView *test1 = [[UIView alloc]initWithFrame:CGRectMake(x, y,width,height)];
于 2013-04-26T12:23:40.483 回答
1

与 point.x 和 point1.x 比较,将较小的 1 作为 x 并对 y 执行相同的操作(与 point.y 和 point1.y 比较,将较小的 1 作为 y)。将 point.x 和 point1.x 之间的差异作为宽度并对高度执行相同操作(point.y 和 point1.y 之间的差异)将解决问题

于 2013-04-26T11:51:08.213 回答
0

尝试用下一个计算视图的矩形:

float x = MIN(point.x, point1.x);
float y = MIN(point.y, point1.y);
float width = fabsf(point.x - point1.x);
float height = fabsf(point.y - point1.y);
CGRect frame = CGRectMake(x, y, width, height);
于 2013-04-26T12:28:38.643 回答