我有子類UIView,並且最初我的視圖將以默認顏色顯示,我需要在觸摸時填充一些不同的顏色(從x軸= 0到用戶觸摸的點),這裏是問題是touchesMoved即使我拖出我的自我觀點範圍它得到這些點,如何限制它只爲我的自我觀點範圍。touchesMoved伸出我的視野範圍
我GOOGLE &嘗試下面的片段,但沒有運氣
if([self pointInside:point withEvent:nil]){
[self fillColor];
}
我touchesMoved方法是如下,
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
endPoint = point;
NSLog(@"moved x: %f,y: %f",point.x,point.y);
if(CGRectContainsPoint([self frame], endPoint)){ // this also not working
[self fillColor];
}
}
任何幫助預先感謝。
事情是上面的代碼片段是在我的視圖類(fillColorView)&我把這個視圖作爲[anyParentViewController addSubView:fillColorView]所以當我使用這個時,anyParentV iewController正在運行,如果我在fillColorView中移動我的手指,即使我將手指拖出邊界到我的fillColorView,它正在我的anyParentViewController中填充顏色。 –
CGPoint pointToMove = [tap locationInView:fillColorView];也使用我的bellow代碼夥計我也創建這種類型的應用程序的iPad中,其中使用可以畫線 –
@GrahamBell設置標籤也爲fillColorView花花公子也見更新的答案.. –