避免UIView触摸延迟



我在我的应用程序中使用UIView的子类。当用户触摸视图时,我需要获得点的坐标;对于这个,我使用:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    currentPoint=[[touches anyObject]locationInView:self];
}

它有一些延迟。谁能给我一个解,让我立刻得到积分?谢谢大家。

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
        self.frame=frame;
        rect=[[NSMutableArray alloc] initWithCapacity:1];
        currentPointsList=[[NSMutableArray alloc]initWithCapacity:1];
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    firstTouchedPoint = [touch locationInView:self];
    NSLog(@"the firstTouched point is %");
    for (int i=0; i<[rect count]; i++) {
    if(CGRectContainsPoint([[rect objectAtIndex:i]CGRectValue], firstTouchedPoint)){
        CGRect firstLineRect = CGRectMake(firstTouchedPoint.x,  
                                   [[rect objectAtIndex:i]CGRectValue].origin.y, 
                                   [[rect objectAtIndex:i]CGRectValue].size.width-firstTouchedPoint.x+[[rect objectAtIndex:i]CGRectValue].origin.x, 
                                   [[rect objectAtIndex:i]CGRectValue].size.height);
        UIImageView *firstLine=[[UIImageView alloc]initWithFrame:firstLineRect];
        firstLine.backgroundColor=[[UIColor blueColor]colorWithAlphaComponent:0.3f];
        [self addSubview:firstLine];
        break;
    }
}

如果你正在使用一个UIScrollView,有一个延迟触摸属性(delayscontent触摸)。你可能需要确保它是NO

最新更新