重新访问时 UIView 很少不旋转的可能原因有哪些?
我将此代码放入我的所有视图控制器中:
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上出现的频率更高。 在模拟器上,我记得这从未发生过。 您知道造成这种情况的可能原因有哪些吗? 先感谢您。
I put this code into all of my 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;
}
and I also have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
I can see that the codes work correctly as they should, but once in a while, there is a rare occasion that the main view controller failed to rotate for landscape mode after I put its view back to be the main view. The chance that it occurs is very rare, but this is nagging me. Moreover, I can see that it occurs more often on the iphone. On the simulator, I recalled it never happen. Do you know what are the possible causes for this? Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了我的iphone程序的原因。
可能的原因之一是内存。 当系统内存不足时,将调用以下方法:
调用此方法时,将卸载“看不见的”UIView。 当您即将再次看到此视图时,设备会重新加载它,但可能是因为您在重新加载时不会调用它的地方设置了参数(用于旋转等)。 您可以使用:
它发生在设备中,因为我们正在谈论真实设备上的真实内存。 使用模拟器时可以使用“硬件>模拟内存警告”。
I found the cause of my iphone program.
One of the possible causes is memory. This method below will be called when the system is low on memory:
An "unseen" UIView is unloaded when this method is called. When you are about to see this view again, the device reloaded it, but maybe because you set the parameters (for the rotation, etc.) in a place where it won't be called when it gets reloaded. You may use:
It occurs in the device because of we are talking real memory on the real device. You can use "Hardware > Simulate Memory Warning" when you are using the simulator.