问题描述
- 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 =>%flocation =>%f ""point.xpoint.y); CGPoint point1 = [recognizer locationOfTouch:1 inView:self.view]; NSLog(@""location X =>%flocation =>%f ""point1.xpoint1.y); NSLog(@""location X =>%flocation =>%f ""xy); UIView *test1 = [[UIView alloc]initWithFrame:CGRectMake(point.x point1.y x y)]; test1.backgroundColor= [UIColor greenColor]; [self.view addSubview:test1];}
需要的功能就是,通过手指触摸指定位置的屏幕,来添加新的视图,还可以让用户用手指划动调整新视图的坐标,(xywh)。
搜索了很多网页也没找到实现方法,请高手帮忙指点,谢谢。
解决方案
使用TouchBegin 和 TouchMove 来实现比较好.
时间: 2024-11-03 04:27:00