Phonegap-ipad 应用程序 - 根据方向调整启动图像
我正在尝试使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这些名称:
更多: http://www.weston-fl.com/blog/?p=840
USE THESE NAMES:
More: http://www.weston-fl.com/blog/?p=840
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