ios - 如何在方向更改时显示新的 ViewController?

标签 ios objective-c

我正在尝试重新创建类似于 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/

相关文章:

html - 减少 phonegap 应用程序 ios 中的 html 文件加载时间?

ios - iPhone 像素坐标问题

ios - (null) 在使用 NSDateFormatter 之后

objective-c - 程序中出现意外的 '@' (Xcode)

ios - 动画导航栏标题文本更改

objective-c - objective-c - 在 drawRect 中绘制带圆角的图像

ios - CollectionViewCell 的 subview 的渐变层仅在 View CONtroller 首次接纳时存在

ios - 在导航 Controller 上推送时 View 变暗

ios - 限制 UIButton 沿 UIBezierPath 路径的移动

ios - SECP256K1 使用 SawTooth Swift