首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >以编程方式更改定向接口

以编程方式更改定向接口
EN

Stack Overflow用户
提问于 2014-03-09 17:31:20
回答 1查看 93关注 0票数 0

在我的iOS应用程序中,界面是通过编程方式将多个UIViews添加到当前屏幕上的UIViewController中创建的。目前,应用程序工作在肖像方向,但我想增加工作能力,在景观。我想改变界面时,应用程序被放置在景观方向。锄头我能做这个吗?

我不能用界面生成器

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-09 20:01:17

您需要通过NSNotificationCenter观察方向的变化,然后处理它。

代码语言:javascript
运行
复制
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];

然后创建处理旋转的方法。

代码语言:javascript
运行
复制
- (void)orientationChanged:(NSNotification *)notification
{
    // Get device orientation
    UIDeviceOrientation deviceOrientation   = [UIDevice currentDevice].orientation;

    if (UIDeviceOrientationIsPortrait(deviceOrientation))
    {
        // Portrait
    }
    else if(UIDeviceOrientationIsLandscape(deviceOrientation))
    {
        // Landscape
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22285516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档