我从主视图的大小制作了一个日志,我在orientation=4
日志上遇到了奇怪的大小。我无法弄清楚问题是什么。这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
- (void)orientationDidChange:(NSNotification *)note
{
int orientation = [[UIDevice currentDevice] orientation];
NSLog(@"orientation=%i -------------------------------",orientation);
CGRect f = self.view.frame; NSLog(@"self.view.frame =(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);
f = self.view.bounds; NSLog(@"self.view.bounds=(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);
f = [[UIScreen mainScreen] applicationFrame]; NSLog(@"main.app.frame =(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);
f = [[UIScreen mainScreen] bounds]; NSLog(@"main.bounds =(%f, %f, %f, %f)",f.origin.x, f.origin.y, f.size.width, f.size.height);
}
结果如下:
orientation=1 -------------------------------
self.view.frame =(0.000000, 20.000000, 320.000000, 460.000000)
self.view.bounds=(0.000000, 0.000000, 320.000000, 460.000000)
main.app.frame =(0.000000, 20.000000, 320.000000, 460.000000)
main.bounds =(0.000000, 0.000000, 320.000000, 480.000000)
orientation=0 -------------------------------
self.view.frame =(0.000000, 20.000000, 320.000000, 460.000000)
self.view.bounds=(0.000000, 0.000000, 320.000000, 460.000000)
main.app.frame =(0.000000, 20.000000, 320.000000, 460.000000)
main.bounds =(0.000000, 0.000000, 320.000000, 480.000000)
orientation=4 -------------------------------
self.view.frame =(0.000000, 20.000000, 320.000000, 460.000000) <== First time size
self.view.bounds=(0.000000, 0.000000, 320.000000, 460.000000) <== First time size
main.app.frame =(0.000000, 20.000000, 320.000000, 460.000000) <== First time size
main.bounds =(0.000000, 0.000000, 320.000000, 480.000000) <== First time size
orientation=2 -------------------------------
self.view.frame =(20.000000, 0.000000, 300.000000, 480.000000)
self.view.bounds=(0.000000, 0.000000, 480.000000, 300.000000)
main.app.frame =(20.000000, 0.000000, 300.000000, 480.000000)
main.bounds =(0.000000, 0.000000, 320.000000, 480.000000)
orientation=4 -------------------------------
self.view.frame =(20.000000, 0.000000, 300.000000, 480.000000) <== Why is it different?
self.view.bounds=(0.000000, 0.000000, 480.000000, 300.000000) <== Why is it different?
main.app.frame =(20.000000, 0.000000, 300.000000, 480.000000) <== Why is it different?
main.bounds =(0.000000, 0.000000, 320.000000, 480.000000) <== Why is it different?
我为解决此问题而采取的步骤如下:
- cmd+right arrow
- cmd+right arrow
- cmd+left arrow