避免UIView触摸延迟

问题描述:

我在我的应用程序中使用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; 
    } 

} 
+0

你可以发布子类触摸方法吗? – 2011-04-08 09:15:51

+0

我写了touchesBegan touchesMoved和Touchesended在那个类。 – ajay 2011-04-08 09:26:03

+0

很难判断延迟源于没有足够的数据。 – 2011-04-08 09:27:55

如果您正在使用一个UIScrollView有延迟触及属性(delaysContentTouches)。你可能想确定这是否。

+0

谢谢Ginamin我会检查... – ajay 2011-04-08 09:35:59

+0

我将我的视图添加到scrollview有没有什么问题,在添加我的视图作为子视图滚动视图我自我。 scrollview.delaysContentTouches = NO ...但它也不能正常工作 – ajay 2011-04-08 09:39:44

+0

+1再次感谢你的回答真的用于我的工作。 – ajay 2011-04-08 10:23:46