5x5グリッドの周りに「石」画像をスワイプする動きをコーディングしようとしています。 つまり、私の石の1つが列3、行1で始まり、下にスワイプすると、列3、行4(NSInteger配列[5] [5])に終わるはずです。 私のような、@implementation {}でアウトレットビューのインスタンス変数を持っている:アニメーションが動作しないUIImageView(ストーン 'オブジェクト')の位置を更新します。
:IBOutlet UIView* _one;
ここで私は、ビュー上で「_one」を下にスワイプここ
- (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;
}
が出力だ時に起こるすべてですここで
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
は何が起こっているのかについて、いくつかのコメントである:
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.
問題の内容を確認できません。それは 'アニメーション:'ブロック内のコードですか? 'move:withView:'メソッドの戻り値を変更する必要がありますか? アニメーションメソッドの[UIView ...]は、私がアニメーション化したいものが、プロセス全体で正常に渡された 'stoneView'であることを理解していますか?この -Anthony
申し訳ありませんが、問題全体を読んでも問題は解決しません。 – amorbytes
アニメーションメソッドの 'animations:'ブロック以外のコードはすべて無視してください。私は自分の石像の位置を更新しようとしています。だからスワイプすれば、その石を動かしてその位置を更新したい。すべてはポジションの保存の点では機能しますが、アニメーションは機能しません。私の石は動いていない、それはちょうどその元の場所に入れて滞在しています。 –
エラーログを含むと私はそれを解決するのに役立ちます – amorbytes