문제

나는 알아낼 수없는 끈적 끈적한 버그를 가지고 있으며, 터치 스마트가 구현되는 방식과 관련이 있다고 생각합니다.

TouchesMoved에서 터치가 어디에 있는지 확인한 다음 (IF 명령문) Touchpoint 근처의 40 x 40 영역에서 SetneedSdisplayWithRect를 호출합니다. DrawRect에서 발생하는 것은 이전에 흰색 이미지가 있으면 검은 이미지가 내려졌으며 그 반대도 마찬가지입니다. 동시에 SetneedSdisplayWithRect를 호출하는 동시에 부울 배열에서 부울 변수를 설정하므로 현재 이미지가 무엇인지 추적하여 반대를 표시 할 수 있습니다. (실제로, 나는 항상 이미지를 뒤집는 것은 아닙니다 ... 나는 첫 번째 터치가 검은 색에서 흰색으로 전환하는 것처럼 무엇을 할 것인지보고, 모든 후속 터치에 흰색 이미지를 넣으므로 그림을 그리는 것과 같습니다. 또는 이미지와 함께 지우기).

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self];
    CGPoint lastTouchPoint = [touch previousLocationInView:self];

    touchX = touchPoint.x;
    touchY = touchPoint.y;

    int lastX = (int)floor((lastTouchPoint.x+0.001)/40);
    int lastY = (int)floor((lastTouchPoint.y+0.001)/40);
    int currentX  = (int)(floor((touchPoint.x+0.001)/40));
    int currentY  = (int)(floor((touchPoint.y+0.001)/40));

    if  ((abs((currentX-lastX)) >=1) || (abs((currentY-lastY)) >=1))
    {
        if ([soundArray buttonStateForRow:currentX column:currentY] == firstTouchColor){
            [soundArray setButtonState:!firstTouchColor row:(int)(floor((touchPoint.x+0.001)/40)) column:(int)(floor((touchPoint.y+0.001)/40))];

            [self setNeedsDisplayInRect:(CGRectMake((CGFloat)(floor((touchPoint.x+0.001)/40)*40), (CGFloat)(floor((touchPoint.y+0.001)/40)*40), (CGFloat)40.0, (CGFloat)40.0))];
        }
    }
}

내 문제는 부울 배열이 내가 내려 놓는 이미지와 함께 쫓겨 난 것 같다는 것입니다. 화면에서 실제로 빨리 드래그하는 경우에만 발생합니다. 결국 부울 배열과 이미지는 동시에 설정하더라도 더 이상 동기화되지 않습니다. 이것을 일으키는 원인이 무엇인지 또는 그것을 고치기 위해 무엇을 할 수 있습니까?

내 drawRect는 다음과 같습니다.

- (void)drawRect:(CGRect)rect {

    if ([soundArray buttonStateForRow:(int)(floor((touchX+0.001)/40)) column:(int)(floor((touchY+0.001)/40))])
        [whiteImage drawAtPoint:(CGPointMake((CGFloat)(floor((touchX+0.001)/40)*40), (CGFloat)(floor((touchY+0.001)/40))*40))]; 
    else
        [blackImage drawAtPoint:(CGPointMake((CGFloat)(floor((touchX+0.001)/40)*40), (CGFloat)(floor((touchY+0.001)/40))*40))]; 


}
도움이 되었습니까?

해결책

나는 이것에 대한 답을 알아 냈습니다. Touchx와 T 따라서 화면에서 빠르게 이동하면 TouchesMoved가 호출 된 다음 Call DrawRect가 발생하면 DrawRect가 TouchX와 Touchy를 사용하기 전에 T

이것을 해결하기 위해 DrawRect에서 Touchx와 T

타다!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top