手机处于横向模式时隐藏标签 [英] Hiding a label when phone is in landscape mode

查看:81
本文介绍了手机处于横向模式时隐藏标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个iPhone应用程序,其下方带有文本标签的图标。我希望在手机旋转到横向模式时隐藏标签,因为没有足够的空间。最简单的方法是什么?

I am creating an iPhone app which has icons with text labels underneath. I want the labels to be hidden when the phone is rotated to landscape mode, as there is not enough space for them. What is the easiest way to do this?

推荐答案

您可以先在viewDidLoad中添加NSNotification以了解设备的方向更改。

You can first add an NSNotification to know orientation change on your device in viewDidLoad.

NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)

当设备知道方向改变时,这将调用旋转功能,然后你只需创建该功能并将你的代码放在里面。

This will call the function "rotated" when device know it's orientation changed, then you just have to create that function and put ur code inside.

func rotated()
{
    if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
    {            
        print("landscape")
        label.hidden = true
    }

    if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
    {
        print("Portrait")
        label.hidden = false
    }

}

解决方案来自< a href =https://stackoverflow.com/questions/25666269/ios8-swift-how-to-detect-orientation-change>IOS8 Swift:如何检测方向变化?

这篇关于手机处于横向模式时隐藏标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆