我在自定義UIView中創建了200x200圓。我正在使用以下腳本在iPad上的屏幕上移動視圖對象。防止視圖對象在用手指觸摸移動時跳躍
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
if([touch view] == newShape)
{
newShape.center = currentPoint;
}
[self.view setNeedsDisplay];
}
一切工作正常,我可以移動屏幕上任何地方的圓圈。但是,如果我沒有碰到圓形物體的死點,它會略微跳躍。通過閱讀代碼,這是非常明顯的,因爲newShape.center
被設置到觸摸發生的任何地方,並最終迅速捕捉到該位置。
我正在尋找一種方法來移動物體而不會捕捉到觸摸位置。我想我會使用xy座標來實現這一點,但我不知道如何實現它。
謝謝!
關閉我的頭頂(沒有代碼,在iPhone上)我想一個簡單的if-then要弄清楚你的手指是否不是死點。只需在[UIView]動畫塊中使用newShape.center行即可。 (和認真,腳本LOL) – CodaFi