再訪時にまれにしか回転していないされていないのUIViewの原因は何ですか?
-
11-09-2019 - |
質問
私は私のviewControllersのすべてにこのコードを配置します:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight) {
CGAffineTransform transform = self.view.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(320/2, 480/2);
// Set the center point of the view to the center point of the window's content area.
self.view.center = center;
// Rotate the view 90 degrees around its new center point.
transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
self.view.transform = transform;
}
私も持っています:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
私は、コードは、彼らが必要として正常に動作しますが、たまに、私がメインビューであることを戻しビューを入れた後、メインビューコントローラは、ランドスケープモードのために回転させるために失敗したことをまれがあることがわかります。それが起こる可能性は非常にまれですが、これは私をしつこいれます。また、私はそれがiPhone上でより頻繁に発生していることがわかります。シミュレータで、私はそれが起こることはありません思い出しました。あなたは、このための原因が何であるか知っていますか?事前にありがとうございます。
解決
私は私のiphoneプログラムの原因を見つけます。
考えられる原因の一つは、メモリです。システムのメモリが不足している場合は、以下のこのメソッドが呼び出されます。
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
「見えない」のUIViewは、このメソッドが呼び出されたときにアンロードされます。あなたがもう一度、このビューを表示しようとしている場合は、デバイスはそれを再ロードしますが、それがリロードされますとき、それは呼び出されません場所で(回転、など)のパラメータを設定するかもしれないので。あなたが使用することができます:
- (void)viewDidLoad {
UIApplication* application = [UIApplication sharedApplication];
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation([MyMath radd:90]);
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, -80, 83);
[self.view setTransform: landscapeTransform];
[super viewDidLoad];
}
私たちは、実際のデバイス上で実メモリを話しているのため、これは、デバイスで発生します。あなたは、シミュレータを使用しているときは、「メモリ警告をシミュレート]> [ハードウェア」を使用することができます。
所属していません StackOverflow