、touch触发点点击屏幕
@property (nonatomic, strong)UIImageView *iv;
- (void)viewDidLoad { [super viewDidLoad]; self.iv = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; self.iv .backgroundColor = [UIColor blackColor]; [self.view addSubview:self.iv];}//开始-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // 把set转成array // NSArray *arr = touches.allObjects; //NSLog(@"开始"); //*********获取单个手指坐标 UITouch*t=[touches anyObject]; CGPoint p = [t locationInView:self.view]; self.iv.center = p; //在控制台输出的NO.1 NSLog(@"开始 %f--%f",p.x,p.y); //NO.2把中心点转为字符串 NSLog(@"开始 %@",NSStringFromCGPoint(p)); //用户点击的数量 NSLog(@"=====%ld",t.tapCount); //*********获取两个 NSArray *arr = touches.allObjects; if (arr.count==2) { UITouch *t1 = arr[0]; UITouch *t2 = arr[1]; CGPoint p1 = [t1 locationInView:self.view]; CGPoint p2 = [t2 locationInView:self.view]; NSLog(@"p1=%@ p2=%@",NSStringFromCGPoint(p1),NSStringFromCGPoint(p2)); }}//移动-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ // NSLog(@"移动"); UITouch*t=[touches anyObject]; CGPoint p = [t locationInView:self.view]; self.iv.center = p; NSLog(@"移动 %@",NSStringFromCGPoint(p));}//结束-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ //NSLog(@"结束"); UITouch*t=[touches anyObject]; CGPoint p = [t locationInView:self.view]; self.iv.center = p; NSLog(@"结束 %@",NSStringFromCGPoint(p));}//因为意外退出-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ NSLog(@"因为意外退出");
}
2、 当用户使用超过一个的触屏点的坐标要勾选
3、超出视图的Bouns不显示
学习ios 重要还是要理清楚思路 在做或者看老师代码的时候 自己多想想为什么 不要自己看着就抄 另外还是要推荐一下 蓝懿IOS这个培训机构 和刘国斌老师刘国斌老师还是很有名气的,听朋友说刘老师成立了蓝懿iOS,,老师讲课方式很独特,能够尽量让每个人都能弄明白,有的比较难懂的地方,如果有的地方还是不懂得话,老师会换个其它方法再讲解,这对于我们这些学习iOS的同学是非常好的,多种方式的讲解会理解得更全面,这个必须得给个赞,嘻嘻,还有就是这里的学习环境很好,很安静,可以很安心的学习,安静的环境是学习的基础,小班讲课,每个班20几个学生,学习氛围非常好,每天都学到9点多才离开教室,练习的时间很充裕,而且如果在练习的过程中有什么困难,随时可以向老师求助,不像其它机构,通过视频教学,有的甚至学完之后都看不到讲师本人,问点问题都不方便,这就是蓝懿与其它机构的区别,相信在刘国斌老师的细心指导下,每个蓝懿学员都能找到满意的工作,加油!
写博客第三十七天;
QQ:565803433