I'm developing an iOS application with latest SDK.
我正在开发一个带有最新SDK的iOS应用程序。
I have set Landscape right orientation as the unique orientation available and I have a question about viewController view.
我已将Landscape右方向设置为可用的唯一方向,我对viewController视图有疑问。
This is my code:
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != AVCaptureVideoOrientationLandscapeRight);
}
- (void)deviceOrientationDidChange:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"Orientation: Landscape Right");
NSLog(@"FRAME: %@", NSStringFromCGRect(self.view.frame));
}
And this is the log that I get:
这是我得到的日志:
Orientation: Landscape Right
FRAME: {{0, 0}, {320, 568}}
Orientation: Landscape Right
FRAME: {{0, 0}, {320, 568}}
My question is about {{0, 0}, {320, 568}}
:
我的问题是关于{{0,0},{320,568}}:
Why am I getting these values?
为什么我会得到这些价值?
I think the correct values would be {{0, 0}, {568, 320}}
.
我认为正确的值是{{0,0},{568,320}}。
4 个解决方案
#1
3
I believe that the frame rects don't react to orientation change.
我相信框架不会对方向变化做出反应。
EDIT: My original solution was overly complicated for your needs. If you're correctly finding the current orientation, then just interpret the width of the rect as the height if you're in landscape mode.
编辑:我原来的解决方案过于复杂,无法满足您的需求。如果您正确找到当前方向,那么只要将您的宽度解释为高度(如果您处于横向模式)。
#2
1
I add this solution to show what happens with frame and bound.
我添加此解决方案以显示框架和绑定发生的情况。
I've added these three methods:
我添加了这三种方法:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect bounds = [view bounds];
NSLog(@"FRAME: %@", NSStringFromCGRect(view.frame));
NSLog(@"BOUNDS: %@", NSStringFromCGRect(bounds));
}
- (void)deviceOrientationDidChange:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"1. Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"1. Orientation: Landscape Right");
NSLog(@"1. FRAME: %@", NSStringFromCGRect(self.view.frame));
NSLog(@"1. BOUNDS: %@", NSStringFromCGRect(self.view.bounds));
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"2. Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"2. Orientation: Landscape Right");
NSLog(@"2. FRAME: %@", NSStringFromCGRect(self.view.frame));
NSLog(@"2. BOUNDS: %@", NSStringFromCGRect(self.view.bounds));
}
- (void)viewDidLayoutSubviews
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"3. Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"3. Orientation: Landscape Right");
NSLog(@"3. FRAME: %@", NSStringFromCGRect(self.view.frame));
NSLog(@"3. BOUNDS: %@", NSStringFromCGRect(self.view.bounds));
}
And this is what I get:
这就是我得到的:
FRAME: {{0, 0}, {320, 568}}
BOUNDS: {{0, 0}, {320, 568}}
3. Orientation: Landscape Right
3. FRAME: {{0, 0}, {320, 568}}
3. BOUNDS: {{0, 0}, {568, 320}}
1. Orientation: Landscape Right
1. FRAME: {{0, 0}, {320, 568}}
1. BOUNDS: {{0, 0}, {568, 320}}
1. Orientation: Landscape Right
1. FRAME: {{0, 0}, {320, 568}}
1. BOUNDS: {{0, 0}, {568, 320}}
Bound changes on viewDidLayoutSubviews:
.
viewDidLayoutSubviews上的绑定更改:
#3
0
Use self.view.bounds instead of self.view.frame
使用self.view.bounds而不是self.view.frame
#4
0
Please change change on your viewController
请更改viewController的更改
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
replace by
SKScene * scene = [MyScene sceneWithSize:CGSizeMake(skView.frame.size.height, skView.frame.size.width)];
#1
3
I believe that the frame rects don't react to orientation change.
我相信框架不会对方向变化做出反应。
EDIT: My original solution was overly complicated for your needs. If you're correctly finding the current orientation, then just interpret the width of the rect as the height if you're in landscape mode.
编辑:我原来的解决方案过于复杂,无法满足您的需求。如果您正确找到当前方向,那么只要将您的宽度解释为高度(如果您处于横向模式)。
#2
1
I add this solution to show what happens with frame and bound.
我添加此解决方案以显示框架和绑定发生的情况。
I've added these three methods:
我添加了这三种方法:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect bounds = [view bounds];
NSLog(@"FRAME: %@", NSStringFromCGRect(view.frame));
NSLog(@"BOUNDS: %@", NSStringFromCGRect(bounds));
}
- (void)deviceOrientationDidChange:(NSNotification*)notification
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"1. Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"1. Orientation: Landscape Right");
NSLog(@"1. FRAME: %@", NSStringFromCGRect(self.view.frame));
NSLog(@"1. BOUNDS: %@", NSStringFromCGRect(self.view.bounds));
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"2. Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"2. Orientation: Landscape Right");
NSLog(@"2. FRAME: %@", NSStringFromCGRect(self.view.frame));
NSLog(@"2. BOUNDS: %@", NSStringFromCGRect(self.view.bounds));
}
- (void)viewDidLayoutSubviews
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == AVCaptureVideoOrientationLandscapeLeft)
NSLog(@"3. Orientation: Landscape Left");
else if (orientation == AVCaptureVideoOrientationLandscapeRight)
NSLog(@"3. Orientation: Landscape Right");
NSLog(@"3. FRAME: %@", NSStringFromCGRect(self.view.frame));
NSLog(@"3. BOUNDS: %@", NSStringFromCGRect(self.view.bounds));
}
And this is what I get:
这就是我得到的:
FRAME: {{0, 0}, {320, 568}}
BOUNDS: {{0, 0}, {320, 568}}
3. Orientation: Landscape Right
3. FRAME: {{0, 0}, {320, 568}}
3. BOUNDS: {{0, 0}, {568, 320}}
1. Orientation: Landscape Right
1. FRAME: {{0, 0}, {320, 568}}
1. BOUNDS: {{0, 0}, {568, 320}}
1. Orientation: Landscape Right
1. FRAME: {{0, 0}, {320, 568}}
1. BOUNDS: {{0, 0}, {568, 320}}
Bound changes on viewDidLayoutSubviews:
.
viewDidLayoutSubviews上的绑定更改:
#3
0
Use self.view.bounds instead of self.view.frame
使用self.view.bounds而不是self.view.frame
#4
0
Please change change on your viewController
请更改viewController的更改
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
replace by
SKScene * scene = [MyScene sceneWithSize:CGSizeMake(skView.frame.size.height, skView.frame.size.width)];