我正在尝试重新创建类似于 iOS 音乐应用的效果,因为当手机从垂直翻转到水平时(音乐应用显示专辑封面),我希望在我的应用中出现一个全新的 View 。而且我似乎无法正常工作。到目前为止,我已经尝试了以下变体:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
TMFHorizontalFavoritesViewController *horizontalVC = [[TMFHorizontalFavoritesViewController alloc] init];
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation)) {
[self presentViewController:horizontalVC animated:YES completion:nil];
}
}
但充其量我似乎得到的只是黑屏。我已经尝试在 Stackoverflow 上使用谷歌搜索和搜索类似的问题,但我似乎无法拼凑出正确的答案。如果有人有任何意见,我们将不胜感激!
最佳答案
如果我可以给新的 iOS 程序员一条建议,那就是永远不要使用 alloc init 实例化 View Controller (有时它是合法的,但新手几乎总是会弄错)。
这就是你如何使用 Storyboard定义的 Controller ,
TMFHorizontalFavoritesViewController *horizontalVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MyIdentifier"];
关于ios - 如何在方向更改时显示新的 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24544760/