横方向への変更後の座標系を変換する方法はありますか?
-
23-08-2019 - |
質問
ビューベースのiPhone OSアプリケーションでは、Iはの横向きする(UIInterfaceOrientationLandscapeRight)に初期縦方向から向きを変えます。しかし、今のx、yの原点(0,0)(代わりに、通常の左上の)の左下ののコーナーにあると私は、座標を必要とする何かをしたいたびに私は再しなければなりません新しい座標系を補正するために計算します。私はまた、新しい座標系内の私の見解は、時々正常に動作していないことに気づきました。だから、私はを左上のコーナーに起源を持つものとして、私の座標の思考を保つことができるように?
解決
あなたが適用の推奨アプローチを行う場合は、
それを回転させるためにあなたのメインビューに変換します:
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;
}
あなたは、このメインビューに追加するサブビューは、標準座標系を使用する必要があります。それは、メインビューに適用される変換サブビューの座標を回転の世話をするだけでなく。これは私のアプリケーションで私のためにうまく機能します。
所属していません StackOverflow