我使用下面的代码在 iOS7 中有单独的横向和纵向视图:
-(void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation {
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
CGRect currentBounds=self.view.bounds;
if (iPadInt==0) {
if (self.interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
self.view=self.landscapeQuestionView;
self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(90));
} else if (self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
self.view=self.landscapeQuestionView;
self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(-90));
} else if (self.interfaceOrientation==UIInterfaceOrientationPortrait) {
self.view=self.portraitQuestionView;
self.view.transform=CGAffineTransformMakeRotation(0);
} else if (self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
self.view=self.portraitQuestionView;
self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(180));
} self.view.bounds=currentBounds;
} else if (iPadInt==1) {
if (self.interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
self.view=self.iPadLandscapeQuestionView;
self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(90));
rotationInt=90;
} else if (self.interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
self.view=self.iPadLandscapeQuestionView;
self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(-90));
rotationInt=90;
} else if (self.interfaceOrientation==UIInterfaceOrientationPortrait) {
self.view=self.iPadPortraitQuestionView;
self.view.transform=CGAffineTransformMakeRotation(0);
rotationInt=0;
} else if (self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
self.view=self.iPadPortraitQuestionView;
self.view.transform=CGAffineTransformMakeRotation((kDeg2Rad)*(180));
rotationInt=0;
} self.view.bounds=currentBounds;
}
}
我知道我应该在 iOS8 中使用 viewWillTransitionToSize 方法,但我不知道如何在该方法中获取这些不同的视图。提前感谢您的帮助。