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. 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开发者_JAVA技巧 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. 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.
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. 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. 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)?
精彩评论