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