对所有人
我正在使用

 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)。
如果有人帮助我,我需要帮助
在此先感谢我用谷歌搜索,但没有得到任何帮助

最佳答案

与point.x和point1.x进行比较,将x减去1,对y进行同样处理(与point.y和point1.y的较小1作为y进行比较)。将point.x和point1.x之间的差异作为宽度,对高度进行相同(point.y和point1.y之间的差异)将解决问题

10-06 02:57