【问题标题】:Set landscape image to uinavegationBar with iOS5使用 iOS5 将横向图像设置为导航栏
【发布时间】:2012-04-08 18:41:33
【问题描述】:

我正在开发具有横向和纵向两种位置的 iOS 应用程序。

使用 iOS5,我想将背景图像设置为自定义 UINavegationBar。

我用过:

if([self.navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {

    [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsPort.png"]  forBarMetrics:UIBarMetricsDefault];
    [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsLand.png"]  forBarMetrics:UIBarMetricsLandscapePhone];
}

我在 viewDiLoad 方法中编写了这段代码,它适用于纵向,但在横向模式下使用相同的图像。

请帮帮我,谢谢。

【问题讨论】:

    标签: ios5 landscape-portrait


    【解决方案1】:

    有条件地设置背景图片如下:

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    
      if (UIDeviceOrientationIsLandscape(toInterfaceOrientation)) {
            [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsLand.png"]  forBarMetrics:UIBarMetricsLandscapePhone];
        }
        else if (UIDeviceOrientationIsPortrait(toInterfaceOrientation)) {
            [self.navBar setBackgroundImage:[UIImage imageNamed:@"TabBarContactsPort.png"]  forBarMetrics:UIBarMetricsDefault];
        }
    }
    

    希望对你有帮助。

    【讨论】:

    • UIBarMetricsLandscapePhone 不起作用。如果我总是使用“forBarMetrics:UIBarMetricsDefault”,你的答案就有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 2016-02-11
    相关资源
    最近更新 更多