2011-04-08 166 views
0

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

回答

6

如果您正在使用一個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