我收听event UIApplicationWillChangeStatusBarOrientationNotification.现在,在加载这个应用程序的过程中,我添加了一些视图,并根据当前方向在我的应用程序中设置它们。
在iOS 5中,如果我在纵向模式下加载应用程序,应用程序工作正常,一旦在纵向模式下完成加载,并且UI对齐并调整大小,它将响应其他对景观或纵向的方向更改。我遇到的问题是:当在横向模式下加载iOS 5,并将iOS 5实际放置在平面上以确保其横向时,我得到了一个可以从横向移动到纵向的OrientationNotification (尽管设备没有变化)。
有什么想法吗?
我支持两个iOS的定向
- (BOOL)shouldAutorotate {
return YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
发布于 2013-03-01 17:37:26
听起来好像iOS 5认为,如果实际上没有物理方向(即上下平整),那么东西应该是纵向的,而iOS 6则不是。为了确定重要时显示内容的方向,我使用了实际的设备方向(如果可用)和状态栏方向(如果设备是扁平的)。例如:
// Get a useful screen orientation.
// If the device is physically in portrait or landscape then
// that is the orientation.
// If it is not, then it is probably flat on a table and use
// the orientation of the status bar which should be set to
// the last physical orientation.
//
// screen Orientation
//------------------------------------------------------------
+ (UIDeviceOrientation) screenOrientation {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation!=UIInterfaceOrientationPortrait
&& orientation!=UIInterfaceOrientationPortraitUpsideDown
&& orientation!=UIInterfaceOrientationLandscapeLeft
&& orientation != UIInterfaceOrientationLandscapeRight) {
// Not known at this time. Use the status bar orientation
orientation = [[UIApplication sharedApplication] statusBarOrientation];
}
return orientation;
}
我不确定这是否对您有直接帮助,但也许在您的通知处理程序中,您可以检查一下实际的状态栏方向。或者,可能通知的时间和状态栏方向的更改不会使其工作。
https://stackoverflow.com/questions/15162021
复制