羊羊羊羊 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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘