美文网首页
iOS开发 - touchBegan事件判断点击的位置在Vie

iOS开发 - touchBegan事件判断点击的位置在Vie

作者: 清蘂翅膀的技术 | 来源:发表于2017-08-29 11:29 被阅读0次

//touch的响应方法

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

CGPointpoint = [[touches anyObject] locationInView:self.view];//convert point to the white layer's coordinates拿到在self.view上但同时在whiteView上的点,下面的同这里一样,不一一解释了

point = [whiteView.layerconvertPoint:point fromLayer:self.view.layer];

//get layer using containsPoint:

if([whiteView.layercontainsPoint:point]) {

//convert point to blueLayer’s coordinates

point = [blueLayer convertPoint:point fromLayer:whiteView.layer];

if([blueLayer containsPoint:point])

{

[[[UIAlertView alloc] initWithTitle:@"Inside Blue Layer"message:nildelegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil] show];

}else{

[[[UIAlertView alloc] initWithTitle:@"Inside White Layer"message:nildelegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil]show];

}

}

//----------华丽丽的分割线,从这里开始是我写的点击的方法,相对来说比上面使用起来更方便点//    CGPoint point=[[touches anyObject]locationInView:self.view];//    CALayer *layer=[whiteView.layer hitTest:point];//    if (layer==whiteView.layer) {//        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"" message:@"Inside white layer" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];//        [alertView show];//    }//    else if (layer==blueLayer){//        UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"" message:@"Inside blue layer" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];//        [alertView show];//    }}

相关文章

网友评论

      本文标题: iOS开发 - touchBegan事件判断点击的位置在Vie

      本文链接:https://www.haomeiwen.com/subject/sblodxtx.html