启动画面图像的方向不正确

时间:2012-04-10 19:45:51

标签: iphone objective-c ios uiimageview splash-screen

我想使用自定义初始屏幕,所以我在我的应用代理

中执行此操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    homeNavigationController = [[UINavigationController alloc] init];
    homeNavigationController.navigationBarHidden = NO;

    [homeNavigationController pushViewController:viewController animated:NO];

    // Add the view controller's view to the window and display.
    [window addSubview:homeNavigationController.view];
    [window makeKeyAndVisible];

    [self animateSplash];

    return YES;
}

- (void)animateSplash {

    CGRect cgRect = [[UIScreen mainScreen] bounds];
    CGSize cgSize = cgRect.size;

    // set default portrait for now, will be updated if necessary
    NSString *imageName = @"splash_screen.png";
    CGRect imageFrame = CGRectMake( 0, 0, cgSize.width, cgSize.height );

    imageStage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    imageStage.frame = imageFrame;


    [window addSubview:imageStage];
    [window bringSubviewToFront:imageStage];

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelay:2];
    [UIView setAnimationDuration:3.0f];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];

    imageStage.alpha = 0.0f;

    [UIView commitAnimations];
}

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

    // remove and clean up splash image view
    [imageStage removeFromSuperview];
    [imageStage release];
    imageStage = nil;

}

这项工作还可以,但由于我的应用程序是横向启动(主页按钮右侧)模式,因此我的启动图像方向设置不正确。

2 个答案:

答案 0 :(得分:1)

只需使用旋转的图像,使其在您的方向上看起来正确。

如果你真的想出于某种原因在代码中这样做,请查看How to Rotate a UIImage 90 degrees?以了解旋转UIImage的不同方法。

答案 1 :(得分:0)

您需要告诉iOS您要在横向模式下启动应用。您可以按照Apple here的说明进行操作。