纵向和横向之间切换

2024-01-11

我拍摄了两个视图,一个是纵向和横向,我想要切换旋转视图,我正在使用下面的代码,但它不起作用,我可能知道我哪里出了问题,因为我是iPhone开发的新手。我还没有实现任何东西在 ViewDidLoad 方法中,我也应该在那里实现任何东西吗?

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        self.portrait.hidden = YES;
        self.landscape.hidden = NO;
    } else  {
        self.portrait.hidden = NO;
        self.landscape.hidden =YES;
    }

    return YES; 
}

I have showed To Images in Two Views One in Horizontal and one in Vertical.... A Sample View

在 ViewController.m 中:-

@interface OrientationTutorialViewController : UIViewController 
{

    IBOutlet UIView *portraitView;
    IBOutlet UIView *landscapeView;

}

@property (nonatomic, retain) IBOutlet UIView *portraitView;
@property (nonatomic, retain) IBOutlet UIView *landscapeView;


@end

IN .h :-

@implementation OrientationTutorialViewController

@synthesize portraitView, landscapeView;


- (void)viewDidLoad 
{
    [super viewDidLoad];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

}

- (void) orientationChanged:(id)object
{  
    UIInterfaceOrientation interfaceOrientation = [[object object] orientation];

    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    {
        self.view = self.portraitView;
    } 
    else 
    {
        self.view = self.landscapeView;
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return YES;
}



- (void)dealloc 
{
    [super dealloc];
}

@end

希望我的回答对您有帮助...如果没有,请告诉我您的 ID,我会将项目发送给您。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

纵向和横向之间切换 的相关文章

  • 覆盖层不与 UITableView 一起滚动 - iOS

    我有一个 UITableView 类 它使用以下方法在转到下一个屏幕时调用加载覆盖 问题是这个加载屏幕不随列表滚动 所以如果你滚动一点并单击某些东西 加载屏幕不会显示 因为它位于顶部 如何让加载屏幕始终保持在 UITableView 的顶部
  • 如何使用 Swift 使用 TouchID?

    Apple 为 iOS 8 的 TouchID 实现提供的文档采用 Objective C 语言 有 Swift 版本吗 Objective C IBAction touchIDAvailable UIButton touchIDAvail
  • 忽略触摸事件,让其下面的视图处理触摸?

    我有一个用户可以触摸的可拖动视图 但它的某些矩形将没有图像 alpha 0 当用户单击透明区域时 我能够在没有 alpha 信息的情况下构造透明区域 我希望透明区域下方的视图 同一类 来检测触摸 我的策略是当用户触摸透明区域时让视图忽略触摸
  • Objective-C – 拥有包含 TestFlight SDK 的 TestFlight 配置

    我已按照 TestFlight 的说明复制 发布 配置 我还使用 TestFlight SDK 从我的应用程序获取实时报告 通过这样做 我必须在我的应用程序中包含一些 TestFlight 代码 当然 我不想在我的应用程序的发布版本中包含此
  • 在 Objective C 的类方法中引用类本身

    我希望我没有跳过 ObjC 手册中的这一部分 但是是否可以从类的一个类方法中引用该类 就像在 PHP 中一样 您将使用 this 来引用当前实例 而 self 引用实例的类 this 的 ObjC 等价物将是 self 那么 PHP 的 s
  • 以编程方式使用 Stack Overflow 进行身份验证

    我想在我的 iPhone 应用程序中添加赞成和反对投票 MyStacks http itunes apple com gb app mystacks id360030953 mt 8 为此 我需要能够使用 Stack Overflow 对用
  • ios水平居中约束问题?

    I am having hard time in learning constraints auto layout in iOS I have used any width any height I have a storyboard sc
  • 如何在 iOS 8 中关闭两个 UIViewController?

    我正在使用 Objective C 开发 iPhone 应用程序 由于我需要一次关闭两个 UIViewController 所以我使用下面的代码 self presentingViewController presentingViewCon
  • UIView晃动动画

    我试图在按下按钮时使 UIView 摇动 我正在调整我找到的代码http www cimgf com 2008 02 27 core animation tutorial window shake effect http www cimgf
  • 在 UIScrollview 上显示缩略图的最佳方法是什么(从服务器下载)

    我想在 UIScrollview 如照片应用程序 上显示许多图像 作为缩略图 所有图像将从服务器下载 据我所知 有几种选择 1 通过创建 UIImageviews 然后将它们添加为主滚动视图上的子视图 2 通过子类化一个UIView类 然后
  • Flutter 应用程序在 iOS 平台的 firebase 电话身份验证中崩溃

    我在我的项目中实现了 Firebase Phone auth 在 Android 端 一切正常 但对于 iOS 端 当我尝试从我的端发送验证码时 应用程序崩溃并失去连接 我已在下面提交了我的代码 主程序 dart class MyApp e
  • BigQuery 未显示链接的 Firebase Analytics 事件日志的任何数据集

    我将我的帐户链接到 Big Query 但 Firebase Analytics 事件不会自动加载到 BigQuery 中 显示 未找到数据集 警告 我的工作进度附在下面 请查收 I have getting firebase Analyt
  • 在 iOS 7 中 viewForHeaderInSection 部分是从 1 开始而不是从 0 开始

    我正在处理UITableView在我的项目中 这个项目是在 Xcode 4 5 中创建的 现在我正在使用 Xcode 5 所以我的问题是何时在 iOS 6 中运行我的项目 viewForHeaderInSection方法部分从 0 开始没问
  • 在 WKWebView 中禁用缩放?

    有谁知道在 WKWebView 中禁用双击和捏缩放的简单方法 我尝试过的任何方法都不起作用 Webview scrollView allowsMagnification false Error value of type WKWebView
  • 詹金斯配置文件问题

    检查依赖关系 找不到与 Nitin xxxxxxx xyzCAppStore 匹配的 iOS 配置文件 Xcode 找不到与 Nitin xxxxxxx xyzCAppStore 匹配的配置文件 安装配置文件 通过将其拖放到 Xcode 的
  • Glib 在 iPhone 应用程序中的使用

    我想基于现有的开源 Objective C 框架开发一个 iPhone 应用程序 但是该框架广泛使用了 glib 库 我找不到一种方法来构建和包含 iPhone 应用程序的 glib 库 非越狱 有什么办法可以做到这一点 或者有没有推荐的方
  • 上传存档错误:“缺少 iOS 发行版签名身份......”

    我正在尝试使用 Xcode 将我的 iOS 应用程序存档上传到 iTunes Connect 但是当我单击 上传到 App Store 时 出现错误 Xcode 尝试查找或生成匹配的签名资产并 由于以下问题未能做到这一点 缺少 iOS 为
  • 致命错误:在 Swift 中解包可选值时意外发现 nil

    所以我试图获取 Swift 中输入字段的文本 这就是我得到的 class ViewController UIViewController IBOutlet var passwordField UITextField IBOutlet var
  • 从超立方体图像中获取文本的确切位置

    使用 tesseract 中的 GetHOCRText 0 方法 我能够检索 html 中的文本 并在 webview 中呈现 html 时 我能够获取文本 但图像中文本的位置与输出不同 任何想法都非常有帮助 tesseract gt Se
  • 节拍匹配算法

    我最近开始尝试创建一个移动应用程序 iOS Android 它将自动击败比赛 http en wikipedia org wiki Beatmatching http en wikipedia org wiki Beatmatching 两

随机推荐