避免UIView触摸延迟

aja*_*jay 0 cocoa-touch objective-c uiview uitouch ios

我正在使用UIView我的应用程序中的子类.当用户触摸视图时,我需要获得该点的坐标; 为此我正在使用:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    currentPoint=[[touches anyObject]locationInView:self];

}
Run Code Online (Sandbox Code Playgroud)

它有一些延迟.任何人都可以给我解决方案立即获得积分吗?谢谢你们.

- (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;
}
Run Code Online (Sandbox Code Playgroud)
-(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;
    }

}
Run Code Online (Sandbox Code Playgroud)

Bea*_*ker 7

如果您使用的是UIScrollView,则会有延迟触摸属性(delaysContentTouches).您可能希望确保不是.