Iphone 重新访问时,UIView很少不旋转的可能原因有哪些?
我将此代码放入所有ViewController中:Iphone 重新访问时,UIView很少不旋转的可能原因有哪些?,iphone,uiviewcontroller,rotation,nib,landscape,Iphone,Uiviewcontroller,Rotation,Nib,Landscape,我将此代码放入所有ViewController中: UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight) { CGAffineTransform transform = self.view.transform;
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];
}
它发生在设备中,因为我们谈论的是真实设备上的真实内存。使用模拟器时,可以使用硬件>模拟内存警告