简体   繁体   English

设备旋转后,视图的变换不会改变

[英]View's transform not changing following device rotation

My application has the view of a UITabBarController added to the window of my AppDelegate which displays the views of a couple of customised UIViewControllers. 我的应用程序在我的AppDelegate窗口中添加了一个UITabBarController的视图,该窗口显示了几个自定义UIViewControllers的视图。 In every view controller I have: 在每个视图控制器中,我都有:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return TRUE;
}

implemented so that the application rotates with the device. 实现,以便应用程序随设备一起旋转。

On one of the view controllers I want to do some comparion between the touch coordinates produced by some customised subview objects and after rotation these are in a rotated coordinate space from the coordinates in the view controller. 在一个视图控制器上,我想对一些自定义子视图对象生成的触摸坐标之间进行一些比较,并在旋转之后将它们置于与视图控制器中坐标相对的旋转坐标空间中。

So I asked a question previously about how best to achieve this and I was advised to make use of the viewController's view's transform to get the coordinates into the same rotation. 因此,我之前曾问过一个有关如何最好地实现这一目标的问题,建议我利用viewController的视图变换来使坐标旋转相同。 Sounded good in principle but when I came to use it things didn't go to plan. 原则上听起来不错,但是当我开始使用它时,事情并没有按计划进行。 So I tried to put in some NSLogs to find out why that might be. 因此,我尝试放入一些NSLogs以找出可能的原因。

In the view controller I placed: 在视图控制器中,我放置了:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    NSLog(@"VC Transform: %@", NSStringFromCGAffineOrientation(self.view.transform));
}

and I found that in every orientation the output is [1, 0, 0, 1, 0, 0] even though the screen is clearly rotating. 我发现,即使屏幕明显旋转,每个方向的输出都是[1、0、0、1、0、0]。 Just to mention at no point am I trying to assign something to it within my code. 只是要提一下,我没有尝试在代码中为其分配某些内容。

So I tried adding: 所以我尝试添加:

NSLog(@"AD Tansform: %@", NSStringFromCGAffineOrientation(mainDelegate.window.transform));

to see if there was anything more interesting was happeing there but found the same result. 看看是否还有其他更有趣的事情,但结果还是一样。 I also tried to add it to one of my other view controllers that isn't doing any work following a rotation and found the same thing. 我还尝试将其添加到我的其他视图控制器中,这些控制器在旋转后不做任何工作,并且发现了相同的东西。

Can anyone think of a reason why the view transform might not be changing? 谁能想到视图转换可能不会改变的原因?

Windows and views' transform property is not modified by the interface rotation. 界面旋转不会修改Windows和视图的transform属性。 That transform is intended to be set by the user. 该转换旨在由用户设置。

To see how the interface is rotated, you can try: 要查看界面的旋转方式,可以尝试:

[[UIDevice currentDevice] orientation]

And subscribe to interface orientation notifications as in this answer: How to subscribe self on the event of Device Orientation(not interface orientation)? 并按照以下答案来订阅接口方向通知: 如何在设备方向(非接口方向)事件上自行订阅?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM