さて、これは初心者の質問ですので、事前にお詫び申し上げます。InterfaceBuilderの画面外にレイアウトしたUIViewがあります。ユーザーがボタンを押すと、このビューを画面上でアニメーション化したいと思います。動作しますが、UIViewのボタンを操作できません。アニメーション化するとビューのみが移動し、実際のオブジェクトはその位置を保持することを読みました。そのため、UIViewのレイヤーの位置を設定しようとしましたが、UIViewメニューの左側に81ピクセル余分に表示されます。これが発生した場合、ボタンを操作できますが、画面の右側と同じ高さにする必要があります。openMenuボタンのIBActionのコードは次のとおりです。
CABasicAnimation *moveView = [CABasicAnimation animationWithKeyPath:@"position"];
moveView.delegate = self;
moveView.duration=0.5;
// If the menu is displayed, close it!
CGPoint currentPosView = [[entirePage layer] position];
CGPoint destView;
[moveView setFromValue:[NSValue valueWithCGPoint:currentPosView]];
if (menuDisplayed) {
// Move right to our destination
destView.x = currentPosView.x;
destView.y = currentPosView.y + 81;
[moveView setToValue:[NSValue valueWithCGPoint:destView]];
// Otherwise, open it
} else {
// Move left to our destination
destView.x = currentPosView.x;
destView.y = currentPosView.y - 81;
[moveView setToValue:[NSValue valueWithCGPoint:destView]];
}
// Animate the view
[[entirePage layer] addAnimation:moveView forKey:@"move"];
// Set the final position of our layer
[[entirePage layer] setPosition:destView];
menuDisplayed = !menuDisplayed;
そして、animationDidStopメソッドで:
CGPoint currentPosMenu = [[menuBar layer] position];
if (menuDisplayed) {
currentPosMenu.x -= 81;
} else {
currentPosMenu.x += 81;
}
[[menuBar layer] setPosition:currentPosMenu];
ヘルプ???