[英]Landscape orientation but portrait frame values?
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. 我已经将横向右方向设置为可用的唯一方向,并且我对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}}
。
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.
如果正确找到当前方向,则在横向模式下,只需将矩形的宽度解释为高度即可。
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:
上的绑定更改viewDidLayoutSubviews:
。
使用self.view.bounds而不是self.view.frame
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)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.