5x5 ızgara etrafında' taş 'görüntüyü kaydırmanın hareketini kodlamaya çalışıyorum. Kısacası, taşlardan biri 3. sütundan başlıyorsa, 1. satır ve ben aşağı doğru kaydırın, 3. satırda, 4. satırda (bir NSInteger dizisi [5] [5]] temel alınarak sonuçlandırılmalıdır. Ben gibi @implementation {} bir Çıkışı Görüntüle örnek değişkeni vardır:UIImageView (bir taş 'nesnesi') 'nin Güncelleştirme konumu Animasyon çalışmıyor
:IBOutlet UIView* _one;
Burada görünümü '_one' aşağıda kaydırma İşte
- (void)swipeDown:(UISwipeGestureRecognizer *)recognizer {
NSLog(@"Swipe Down");
UIView *view = recognizer.view;
if (view == _one) {
_currentCol = stoneOneColumn;
_currentRow = stoneOneRow;
_state = (BoardCellState)BoardCellStateStoneOne;
NSLog(@"Got it 3");
} else if (view == _two) { // code for '_two' }
[self move:CGPointMake(0, 1) withView:view];
}
- (void)move:(CGPoint)direction withView:(UIView*)stoneView {
NSLog(@"Got it 5");
CGFloat oldCol = _currentCol;
CGFloat oldRow = _currentRow;
while ([self indexValid:_currentCol y:_currentRow]) {
NSLog(@"Got it 5.5");
CGFloat newCol = _currentCol + direction.x;
CGFloat newRow = _currentRow + direction.y;
if ([self indexValid:newCol y:newRow]) {
NSLog(@"Got it 5.75");
_currentCol = newCol;
_currentRow = newRow;
} else {
NSLog(@"Got it close to 6");
_currentCol = newCol;
_currentRow = newRow;
break;
}
}
NSLog(@"Got it 6");
[_board setCellState:BoardCellStateEmpty forColumn:oldCol
andRow:oldRow];
[_board setCellState:_state forColumn:_currentCol
andRow:_currentRow];
NSLog(@"Got it 7");
[UIView animateWithDuration:0.8
delay:1.0
options:UIViewAnimationOptionCurveLinear
animations:^{
CGRect rect = stoneView.frame;
rect.origin.x =
_frame.origin.x + (_currentCol*61.5);
rect.origin.y =
_frame.origin.y + (_currentRow*61.5);
}
completion:^(BOOL finished) {
NSLog(@"Done finally");
}];
}
- (BOOL)indexValid:(NSInteger)x y:(NSInteger)y {
NSLog(@"Got it 8");
BOOL indexValid = TRUE;
if ((x < 0) || (x > 4) || (y < 0) || (y > 4)) {
NSLog(@"Got it 10");
indexValid = FALSE;
return indexValid;
} else
return indexValid;
}
çıkışı var ne olur her şey
1. BoardCellState is an enum (...StoneOne or ...StoneTwo) signifies the
state of the stone (is the view I'm animating one or two).
2. The while loop runs through the numerical positions, using the
indexValid method to break it when either col or row positions exceed
the _board[5][5] 'boundary'.
3. There are setter and getter methods in another file for stone positions.
I set the Empty state to the old column and row, and set the current
state to the new column and row.
4. THEN I perform the animation! But the problem is, the stone on my
iPhone (when I test it, that is) doesn't move at all, even though
the output goes through this entire process. That's where I'm stuck.
: Burada
2016-04-04 01:52:22.358 Twinstones[8672:907] Swipe Down
2016-04-04 01:52:22.363 Twinstones[8672:907] Got it 3
2016-04-04 01:52:22.365 Twinstones[8672:907] Got it 5
2016-04-04 01:52:22.367 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.368 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.370 Twinstones[8672:907] Got it 5.5
2016-04-04 01:52:22.372 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.374 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.375 Twinstones[8672:907] Got it 5.75
2016-04-04 01:52:22.377 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.379 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.380 Twinstones[8672:907] Got it 5.5
2016-04-04 01:52:22.382 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.384 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.385 Twinstones[8672:907] Got it 5.75
2016-04-04 01:52:22.387 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.389 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.392 Twinstones[8672:907] Got it 5.5
2016-04-04 01:52:22.393 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.395 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.397 Twinstones[8672:907] Got it 5.75
2016-04-04 01:52:22.398 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.400 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.402 Twinstones[8672:907] Got it 5.5
2016-04-04 01:52:22.403 Twinstones[8672:907] Got it 8
2016-04-04 01:52:22.405 Twinstones[8672:907] Got it 9
2016-04-04 01:52:22.407 Twinstones[8672:907] Got it 10
2016-04-04 01:52:22.409 Twinstones[8672:907] Got it close to 6
2016-04-04 01:52:22.411 Twinstones[8672:907] Got it 6
2016-04-04 01:52:22.412 Twinstones[8672:907] Got it 7
2016-04-04 01:52:22.416 Twinstones[8672:907] Done finally
neler üzerinde bazı yorumlar
Sorunun ne olduğunu anlayamıyorum. 'Animasyonlar:' bloğu içindeki kod mu? 'move: withView:' yönteminin dönüş değerini değiştirmem gerekiyor mu? Animasyon yönteminin [UIView ...], canlandırmak istediklerimin, işlem boyunca başarıyla geçtiğim 'stoneView' olduğunu anlıyor mu? Bu -Anthony
Üzgünüz ancak hatanın ne beni anlamadın hâlâ tüm soru değil okuma. – amorbytes
Dolayısıyla, tüm kodu göz ardı etmeyin, ancak animasyon yöntemindeki 'animasyonlar:' bloğunu göz ardı edin. Taş resmimin konumunu güncellemeye çalışıyorum. Bu yüzden kaydırırsam, o taşının yerini değiştirmesini ve güncellemesini istiyorum. Her şey konum depolama açısından çalışır, ancak animasyon çalışmıyor. Taşım hareket etmiyor, sadece orijinal yerinde kalıyor. –
hata günlüğü dahil etmek için bana yardımcı olacaktır – amorbytes