2014-03-06 49 views
0

拖着我已經準備和檢查到GitHub的a simple test case用於拖動定製UIView縮放自定義的UIView打破了touchesMoved

app screenshot

它運作良好,並拖動中實現的Tile.m爲:

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event 
{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint location = [touch locationInView:self]; 
    CGPoint previous = [touch previousLocationInView:self]; 
    self.frame = CGRectOffset(self.frame, 
           (location.x - previous.x), 
           (location.y - previous.y)); 
} 

然而,瓷磚太大,my actual game(我將不得不調整它們的縮放比例,一旦遊戲板在UIScrollView無論如何放大):

app screenshot

所以我擴展我的自定義UIView s下降致電

tile.transform = CGAffineTransformMakeScale(.5, .5); 

大小的變化,但由於所需的瓷磚突然拖「的兩倍快」:

app screenshot

也許touchesMoved代碼(一個或多個。上面)應該調整,但我不確定那裏的操作是由什麼打破的?

回答

0

沒關係,我已經找到了解決辦法:

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

    if (!CGAffineTransformIsIdentity(self.transform)) { 
     location = CGPointApplyAffineTransform(location, self.transform); 
     previous = CGPointApplyAffineTransform(previous, self.transform); 
    } 

    self.frame = CGRectOffset(self.frame, 
           (location.x - previous.x), 
           (location.y - previous.y)); 
}