ビューベースの iPhone OS アプリケーションで、向きを最初の縦向きから横向き(UIInterfaceOrientationLandscapeRight) に変更します。しかし、現在、x、y 原点 (0,0) は(通常の左上ではなく)左下隅にあり、座標を含む何かを実行するたびに、新しい座標を補正するために再計算する必要があります。システム。また、新しい座標系内のビューが時々正常に動作しないことにも気付きました。それで、向きを切り替えた直後に座標系を一度だけ変換して、座標が左上隅にあると考え続けることができる方法はありますか?
4914 次
1 に答える
10
メイン ビューを回転させるために変換を適用するという推奨される方法を実行する場合:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight)
{
CGAffineTransform transform = primaryView.transform;
// Use the status bar frame to determine the center point of the window's content area.
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
CGPoint center = CGPointMake(60.0, bounds.size.height / 2.0);
// Set the center point of the view to the center point of the window's content area.
primaryView.center = center;
// Rotate the view 90 degrees around its new center point.
transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
primaryView.transform = transform;
}
このメイン ビューに追加するサブビューは、標準の座標系を使用する必要があります。メイン ビューに適用される変換は、サブビューの座標の回転も処理します。これは、私のアプリケーションではうまく機能します。
于 2009-05-22T12:18:21.433 に答える