iOS - Detecting touches in a UIView?

前端 未结 4 565
无人共我
无人共我 2021-01-12 01:55

So I have a Subclass of UIView that is suppose to detect touches. The view detect touches only if the touches started inside the current view. When the touches start outside

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 02:17

    Try this....

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        for(UITouch *touch in touches)
        {
            CGPoint touchPointFirstBtn = [touch locationInView:self.ChordView];
            if(CGRectContainsPoint(_btnC.frame, touchPointFirstBtn))
            {
                if (!_btnC.isHighlighted)
                {
                    if(!Boolean)
                    {
                        title = @"C";
                        [_tlbView reloadData];
                        NSLog(@"%@",@"touches C");
    
                    }
                    [_btnC setHighlighted:YES];
                    Boolean = YES;
    
                }
            }
            else
            {
                [_btnC setHighlighted:NO];
                Boolean = NO;
            }
    }
    

提交回复
热议问题