首页 文章

ipad风景/肖像图像

提问于
浏览
2

我正在研究ipad app开发的UI问题(关于图像) . 我已经阅读了苹果开发网站上的一些文件,但我找不到任何有关它的信息 .

是否有图像文件的文件约定来区分系统应为Landscape / Portrait加载哪个图像 . 因为我看到用于启动图像,我们可以使用“MyLaunchImage-Portrait.png”和“MyLaunchImage-Lanscape.png” . 我试图将“-Landscape”,“ - Portrait”,“-Landscape~ipad”,“-Portrait~ipad”添加到其他图像中以供一般使用,但它失败了 .

有没有人以前遇到过这个问题?

1 回答

  • 1

    不幸的是,除了iPad的发布图像之外,没有标准惯例 . 但是,您可以使用 NSNotificationCenter 来监听方向更改事件并相应地对其进行响应 . 这是一个例子:

    - (void)awakeFromNib
    {
        //isShowingLandscapeView should be a BOOL declared in your header (.h)
        isShowingLandscapeView = NO;
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(orientationChanged:)
                                                     name:UIDeviceOrientationDidChangeNotification
                                                   object:nil];
    }
    
    - (void)orientationChanged:(NSNotification *)notification
    {
        UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
        if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
            !isShowingLandscapeView)
        {
            [myImageView setImage:[UIImage imageNamed:@"myLandscapeImage"]];
            isShowingLandscapeView = YES;
        }
        else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&
                 isShowingLandscapeView)
        {
            [myImageView setImage:[UIImage imageNamed:@"myPortraitImage"]];
            isShowingLandscapeView = NO;
        }
    }
    

相关问题