現在、私はiPad用の描画アプリで作業しています。私は同じ場所に描画エリアを維持しながら、それが異なる向きに置かれているときに、アプリケーション内のツールバーを再配置して回転させる必要があります。サイドローテーションによる手動回転方法
これを行うには、hereメソッドが見つかりました。回転の変化を監視するためにNSNotificationCenterを使用します。これはカスタムのdidRotate:メソッドを呼び出し、UIDeviceOrientationに基づいてツールバーを回転させ、位置を変更します。
この部分は正常です。ただし、iPadのサイドスイッチが方向を固定するために使用されている場合は、いつでもツールバーの位置を変更することができます。
たとえば、アプリケーションを横向きに開始して縦向きに回転すると、ツールバーは画面の下に移動します。しかし、スライドスイッチを操作するとすぐに、画面の横方向に画面の横に移動します。
私がこれに使用している方法は以下の通りです。
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
UIInterfaceOrientation interfaceOrientation;
bool orientationFound = YES;
if (deviceOrientation == UIDeviceOrientationPortrait) {
interfaceOrientation = UIInterfaceOrientationPortrait;
} else if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown) {
interfaceOrientation = UIInterfaceOrientationPortraitUpsideDown;
} else if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
interfaceOrientation = UIInterfaceOrientationLandscapeRight;
} else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
interfaceOrientation = UIInterfaceOrientationLandscapeLeft;
} else {
orientationFound = NO;
}
if (orientationFound) {
[self.toolbar changeToOrientation:interfaceOrientation withDuration:.25];
[self.tutorialOverlay changeToOrientation:interfaceOrientation];
}
}
- (void)changeToOrientation:(UIInterfaceOrientation)orientation withDuration:(float)duration {
float angle;
CGPoint origin;
if (orientation == UIInterfaceOrientationPortrait) {
angle = portraitAngle;
origin = self.portraitOrigin;
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
angle = portraitUpsideDownAngle;
origin = self.portraitUpsideDownOrigin;
} else if (orientation == UIInterfaceOrientationLandscapeLeft) {
angle = landscapeLeftAngle;
origin = self.landscapeLeftOrigin;
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
angle = landscapeRightAngle;
origin = self.landscapeRightOrigin;
}
[UIView animateWithDuration:duration animations:^{
self.transform = CGAffineTransformMakeRotation(angle);
CGRect rect = self.frame;
rect.origin = origin;
self.frame = rect;
}];
}
私は前にその方法を試してみたとの通知ベースのアプローチを使用した場合、その後、さらに問題がありました。たとえば、描画領域の境界とフレームプロパティが一致しない場合があります。また、異常な描画異常も発生しました。 – robhasacamera
あなたは正しいです。ビューにトランスフォームがあるときはフレームが定義されていないので、トランスフォームする場合は境界に頼らざるを得ません。 –