iPad 上 iOS 5 横向模式下的导航栏背景图像
我为此苦苦挣扎了一段时间,但找不到任何有相关问题的人。 我的问题是,在 iPad 上为横向模式加载的背景图像不是正确的(它加载图像的纵向版本)。 在 iPhone 或 iPod 上,它可以正常工作。
我在 AppDelegate 文件上使用的代码如下:
if ( [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0 ) {
// Create resizable images
UIImage *gradientImageP = [[UIImage imageNamed:@"header"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *gradientImageL = [[UIImage imageNamed:@"header-Landscape"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:gradientImageP
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:gradientImageL
forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:0 green: 0 blue:0 alpha:1]];
}
问题出在这一行?
[[UINavigationBar appearance] setBackgroundImage:gradientImageL
forBarMetrics:UIBarMetricsLandscapePhone];
我的图像名称如下:
- header-Landscape~iphone.png
- header-Landscape@2x~iphone.png
- header-Landscape~ipad.png
- header~iphone.png
- header@2x~iphone.png
- header~ipad
编辑:屏幕截图导航栏上的问题:
- iPhone 肖像: http://imageshack.us/photo/my-images/200/iphoneportrait。 png/
- iPhone 风景: http://imageshack.us/photo/my-images/193/iphonelandscape。 png/
- iPad 肖像: http://imageshack.us/photo/my-images/62/ipadportrait。 png/
- iPad 横向: http://imageshack.us/photo/my-images/200/ipadlandscape。 png/
有人遇到这个问题吗? 我对如何解决这个问题持开放态度,tkz
Im struggling with this for a while and i cant find anyone with a related issue.
My problem is that the background image that gets loaded on for the landscape mode on the iPad its not the correct one (it loades the portrait version of the image).
On the iphone or iPod it work as its supposed to.
The code im using on my AppDelegate file is the following:
if ( [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0 ) {
// Create resizable images
UIImage *gradientImageP = [[UIImage imageNamed:@"header"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *gradientImageL = [[UIImage imageNamed:@"header-Landscape"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:gradientImageP
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:gradientImageL
forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:0 green: 0 blue:0 alpha:1]];
}
The problem is in this line?
[[UINavigationBar appearance] setBackgroundImage:gradientImageL
forBarMetrics:UIBarMetricsLandscapePhone];
My images names are the following:
- header-Landscape~iphone.png
- header-Landscape@2x~iphone.png
- header-Landscape~ipad.png
- header~iphone.png
- header@2x~iphone.png
- header~ipad
Edit: Screenshots of the problem on the navigation bar:
- iPhone portrait:
http://imageshack.us/photo/my-images/200/iphoneportrait.png/ - iPhone landscape:
http://imageshack.us/photo/my-images/193/iphonelandscape.png/ - iPad portrait:
http://imageshack.us/photo/my-images/62/ipadportrait.png/ - iPad landscape:
http://imageshack.us/photo/my-images/200/ipadlandscape.png/
Anyone with this issue?
Im open to ideas on how to solve this, tkz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用此代码:
Just use this Code:
附加〜iPad适用于纵向模式吗?
这不适合我。您是否还必须指定 ~iPhone 才能使其正常工作?
我通过执行“但对于横向模式,它使用纵向图像并重复最后一个像素列来完成缺失的部分”获得了适用于 iPad 的单独图像
,因此对您的问题没有好处,尽管这可能对其他读者有用。
Does appending ~iPad work for the portrait mode?
It isn't for me. Do you also have to specify ~iPhone to get it to work?
I got a separate image working for the iPad by doing
But for landscape mode it uses the portrait image and repeats the last pixel column to complete the missing portion, so no good for your problem although this may be of use for other readers.
我无法管理适用于 iPad 的旋转外观方法。即使正确调整了导航栏框架的大小,图形也不会改变。最后,我挂钩了所有控制器的
viewWillAppear:animated
和willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientationuration:(NSTimeInterval)duration
方法,以简单地调用setBackgroundImage:< /code> 在 iPad 上使用正确的版本。丑陋,但有效。
这可能是一个值得向 Apple 报告的错误。定义本身的名称也很令人困惑,
UIBarMetricsLandscapePhone
在 iPad 上没有意义,并且您的默认应用程序方向可能是横向的!I wasn't able to manage the appearance method working for the iPad with rotation. Even though the frame of the navigation bar is resized correctly, the graphic doesn't change. In the end I hooked the
viewWillAppear:animated
andwillAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
methods of all my controllers to simply callsetBackgroundImage:
with the correct version on the iPad. Ugly, but works.It's possible this might be a bug worth reporting to Apple. The names of the defines themselves are also confusing,
UIBarMetricsLandscapePhone
doesn't make sense on iPads and your default app orientation could be landscape!我认为你需要做这样的事情:
I think you need to do something like this: