处理 ios 设备方向 [英] handling ios device orientation

查看:29
本文介绍了处理 ios 设备方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 uiviews 有问题,具体取决于设备方向...

I am having issues with my uiviews depending on the devices orientation...

我遇到的主要问题是

UIDeviceOrientationFaceUp
UIDeviceOrientationFaceDown

搞乱了我的视图我只想支持纵向和横向(左右),所以如果设备改变方向,我的视图会正确地改变自己..

are messing with my view I only want to support Portrait and landscape (left right) so if the device changes orientation my view alters itself correctly..

这是我目前实施的.基本上它是一个从屏幕底部向上滚动的 UIView,在这个视图中有几个按钮,用户可以选择加载不同的视图.

this is what I have implemented at the moment. Basicly its a UIView that scrolls up from the bottom of the screen and has several buttons in this view that the user is able to select to load a different view.

#pragma jumpBarButtons
- (void)jumpBarButtonPosition
{

    //orientation stuff
    if (jumpBar.isViewLoaded) {

        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];


        switch (orientation) {
            case UIDeviceOrientationPortrait:
            {
                NSLog(@"Portrait");

                // Row one
                jumpButton1.frame = CGRectMake(18.45, 23.0, 57.0, 57.0);
                jumpButton2.frame = CGRectMake(93.9, 23.0, 57.0, 57.0);
                jumpButton3.frame = CGRectMake(169.35, 23.0, 57.0, 57.0);
                jumpButton4.frame = CGRectMake(244.8, 23.0, 57.0, 57.0);
                // Row tow
                jumpButton5.frame = CGRectMake(18.45, 95.0, 57.0, 57.0);
                jumpButton6.frame = CGRectMake(93.9, 95.0, 57.0, 57.0);
                jumpButton7.frame = CGRectMake(169.35, 95.0, 57.0, 57.0);
                jumpButton8.frame = CGRectMake(244.8, 95.0, 57.0, 57.0);
                // Row three
                jumpButton9.frame = CGRectMake(18.45, 167.0, 57.0, 57.0);
                jumpButton10.frame = CGRectMake(93.9, 167.0, 57.0, 57.0);
                jumpButton11.frame = CGRectMake(169.35, 167.0, 57.0, 57.0);
                jumpButton12.frame = CGRectMake(244.8, 167.0, 57.0, 57.0);
                // Row four
                jumpButton13.frame = CGRectMake(18.45, 239.0, 57.0, 57.0);
                jumpButton14.frame = CGRectMake(93.9, 239.0, 57.0, 57.0);
                jumpButton15.frame = CGRectMake(169.35, 239.0, 57.0, 57.0);
                jumpButton16.frame = CGRectMake(244.8, 239.0, 57.0, 57.0);
            }
                break;

case UIDeviceOrientationLandscapeLeft:
            case UIDeviceOrientationLandscapeRight:
            {
                viewSpaceHeight = 207;
                viewSpaceWidth = 480;

                // Row one
                jumpButton1.frame = CGRectMake(19.7, 9.0, 57.0, 57.0);
                jumpButton2.frame = CGRectMake(96.42, 9.0, 57.0, 57.0);
                jumpButton3.frame = CGRectMake(173.13, 9.0, 57.0, 57.0);
                jumpButton4.frame = CGRectMake(249.84, 9.0, 57.0, 57.0);
                jumpButton5.frame = CGRectMake(326.55, 9.0, 57.0, 57.0);
                jumpButton6.frame = CGRectMake(403.26, 9.0, 57.0, 57.0);
                // Row tow
                jumpButton7.frame = CGRectMake(19.7, 75.0, 57.0, 57.0);
                jumpButton8.frame = CGRectMake(96.42, 75.0, 57.0, 57.0);
                jumpButton9.frame = CGRectMake(173.13, 75.0, 57.0, 57.0);
                jumpButton10.frame = CGRectMake(249.84, 75.0, 57.0, 57.0);
                jumpButton11.frame = CGRectMake(326.55, 75.0, 57.0, 57.0);
                jumpButton12.frame = CGRectMake(403.26, 75.0, 57.0, 57.0);
                // Row three
                jumpButton13.frame = CGRectMake(19.7, 141.0, 57.0, 57.0);
                jumpButton14.frame = CGRectMake(96.42, 141.0, 57.0, 57.0);
                jumpButton15.frame = CGRectMake(173.13, 141.0, 57.0, 57.0);
                jumpButton16.frame = CGRectMake(249.84, 141.0, 57.0, 57.0);

            }
                break;
//..

如果纵向有 16 个 4,4,4,4 图标,那就差不多了,如果横向,则图标是 6,6,4.如果设备面朝上或面朝下翻转会发生什么,所有这些按钮视图都会消失.. 我能做些什么来阻止这种情况,我们将不胜感激.

thats pretty much it if in portrait there are 16 4,4,4,4 icons, if landscape then the icons are 6,6,4. what happens if the device is flipped faceup or facedown, all of these button views disappear.. what can I do to stop this, any help would be gretly appreciated.

推荐答案

改用 UIInterfaceDirection.它是 UIApplication 类,它只包含以下值

Use UIInterfaceDirection instead. Its part of the UIApplication class and it contains only the following values

typedef enum {
   UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
   UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
   UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
   UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
} UIInterfaceOrientation;

您可以像这样轻松检查当前的方向:

You can easily check your current orientation like this:

[[UIApplication sharedApplication] statusBarOrientation] 

这篇关于处理 ios 设备方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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