羊羊羊羊 2013-04-27 02:24 采纳率: 0%
浏览 3207

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条回答 默认 最新

  • ReyZhang 移动开发领域新星创作者 2013-04-27 03:09
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教