Phonegap-ipad 应用程序 - 根据方向调整启动图像

发布于 2024-11-08 22:44:41 字数 1482 浏览 0 评论 0原文

我正在尝试使用phonegap 探索ipad dev。我现在遇到的问题是,

我有针对不同方向的四种不同的启动图像。当应用程序启动时,会暂时显示正确的启动图像。之后,phonegap 尝试加载 default.png 的 imageview 并显示它,直到 webview 完全加载。问题就在这里。图像视图根据当前方向自动旋转。因此,如果当前方向是 LandscapeLeft,imageview 在显示它之前会尝试旋转 default.png,这不是我想要的,这就是为什么我有不同的启动图像。所以实际上,您将有一个 Landscapeleft.png,然后是自动旋转的在我看到 webview 之前,default.png 。

所以我尝试像这样更改phonegapdelegate(在applicationDidFinishLaunching中)

UIImage* image=nil;
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight ){
    NSLog(@"In default5");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default5" ofType:@"png"]];
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
    NSLog(@"In default6");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default6" ofType:@"png"]];
}

if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown ){
    NSLog(@"In default7");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default7" ofType:@"png"]];
}
imageView = [[UIImageView alloc] initWithImage:image];
[image release];

它不起作用,在调试时我发现状态栏方向始终是纵向的。这可能是因为phonegap尝试在同一个applicationDidFinishLaunching方法中将纵向设置为状态栏方向(在加载此图像视图之前)。

有人可以告诉我如何使用正确的图像加载图像视图吗?

I am trying to explore ipad dev using phonegap. The problem that i have now is,

I have four different launch images for different orientations. When the app is launched, the correct launch image is being shown for a moment. After this,phonegap tries to load a imageview with default.png and displays it till webview is fully loaded. The problem lies here.. The imageview is autorotated based on the current orientation. So if the current orientation is LandscapeLeft, imageview tries to rotate default.png before displaying it Which is not i wanted and that is why i have different launch images.So in effect, you will have a landscapeleft.png and then the auto-rotated default.png before i get to see the webview.

So i tried changing the phonegapdelegate like this (in applicationDidFinishLaunching)

UIImage* image=nil;
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight ){
    NSLog(@"In default5");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default5" ofType:@"png"]];
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
    NSLog(@"In default6");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default6" ofType:@"png"]];
}

if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown ){
    NSLog(@"In default7");
    image = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default7" ofType:@"png"]];
}
imageView = [[UIImageView alloc] initWithImage:image];
[image release];

It didn't work and upon debugging i found that the statusbarorientation is always portrait. That may be because phonegap tries to set portrait as the statusbarorientation in the same applicationDidFinishLaunching method(before loading this image view).

Can someone tell me how to load the image view with correct image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾忌 2024-11-15 22:44:41

使用这些名称:

  • Default-LandscapeLeft-ipad.Png
  • Default-LandscapeRight-ipad.Png
  • Default-Portrait-ipad.Png
  • Default-PortraitUpsideDown-ipad.Png

更多: http://www.weston-fl.com/blog/?p=840

USE THESE NAMES:

  • Default-LandscapeLeft-ipad.Png
  • Default-LandscapeRight-ipad.Png
  • Default-Portrait-ipad.Png
  • Default-PortraitUpsideDown-ipad.Png

More: http://www.weston-fl.com/blog/?p=840

素手挽清风 2024-11-15 22:44:41

applicationDidFinishLaunching 对于应用程序来说还太早,无法从操作系统接收方向更改通知。因此您无法在这里确定方向。

因此,最好的解决方案是在能够确定当前方向的生命周期阶段执行此操作。在我的例子中,webViewDidStartLoading

applicationDidFinishLaunching is too early for the app to receive orientation change notifications from the os. Hence you cannot determine the orientation here.

So the best possible solution is to do it in a lifecycle stage which is capable of determining the current orientaion.In my case, webViewDidStartLoading

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文