iphone - 如何使用 UIButton 上的代码解锁横向模式?

标签 iphone objective-c ios xcode landscape

目前,我的整个应用程序处于纵向模式,并且仅限于此。我希望仅在点击一个按钮时启用横向,然后在点击另一个按钮时返回纵向。

我该怎么做?

谢谢

詹姆斯

最佳答案

在您的 View .m 文件中,您应该在底部看到一个函数:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   // Return YES for supported orientations
   if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
   } else {
       return YES;
   }
}

更改适当的方向以使其正确并在按钮中引用它。或者将 if then 复制并粘贴到按钮中。应该可以了。

关于iphone - 如何使用 UIButton 上的代码解锁横向模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7377333/

相关文章:

ios - 如何在 UNNotificationRequest 中设置重复间隔和触发日期

iphone - 在 iOS 中获取当前温度

iphone - 使用模式过滤数组

ios - 如何触发 UISearchBar 委托(delegate)单次?

iphone - 使用 UISwipeGestureRecognizer 滑动 View

iphone - 如何在 iOS 5 中移除 UITabbaritem 的渐变/投影

ios - AsyncDisplayKit ASButtonNode setTitle 不起作用

objective-c - Cocoa:绑定(bind)到 XIB 的 NSMutableString 不会更新,但 NSString 绑定(bind)会更新

iphone - 设备特定的唯一标识符

ios - 使用图像初始化对象