羊羊羊羊 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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器