2 u010321179 u010321179 于 2013.04.27 10:24 提问

UITapGestureRecognizer添加新view

获取触摸的代码:

 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)。
搜索了很多网页也没找到实现方法,请高手帮忙指点,谢谢。

1个回答

zhanglei5415
zhanglei5415   Rxr 2013.04.27 11:09

使用TouchBegin 和 TouchMove 来实现比较好.

Csdn user default icon
上传中...
上传图片
插入图片