如何在iOS上旋转自定义启animation面?

我的启animation面正在工作,但我的应用程序在横向模式下工作,启animation面以默认肖像模式显示。

我如何启动应用程序,以便启动屏幕像风景模式之间旋转我的应用程序?

我使用下面的代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Overriden to allow any orientation. if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES; else { return NO; } } 

和启animation面

 -(void)displayScreen { UIViewController *displayViewController=[[UIViewController alloc] init]; displayViewController.view = displaySplashScreen; [self presentModalViewController:displayViewController animated:NO]; [self performSelector:@selector(removeScreen) withObject:nil afterDelay:3.0]; } -(void)removeScreen { [[self modalViewController] dismissModalViewControllerAnimated:YES]; } 

但是我怎样才能把旋转显示屏幕内?

@zoul – 爱这个解决scheme到目前为止。 但是,如果/当这个视图有任何子视图 – 他们不显示。 有任何想法吗?

更新:

通过向在-startupImageWithOrientation:创build的UIView添加子视图来解决此问题-startupImageWithOrientation: not self.view。

 - (UIView *)startupImageWithOrientation:(UIInterfaceOrientation)io{ UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]]; UIView *aView = [[UIImageView alloc] initWithImage:img]; [aView setFrame:[[UIScreen mainScreen] applicationFrame]]; // define the version number label self.versionNumberLabel_iPadSplashScreen.text = [NSString stringWithFormat:@"Version %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]; [aView addSubview:self.versionNumberLabel_iPadSplashScreen]; return [aView autorelease]; } 

啊哈。 如果你想显示你自己的启animation面,你应该创build一个特殊的视图控制器,你已经做了。 我认为你可以简化自动查询代码:

 - (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) foo { return YES; // all interface orientations supported } 

现在你必须考虑不同方向的启animation面。 你有一个单独的景观和肖像飞溅图像? 如果是的话,你可以做这样的事情:

 - (UIView*) startupImageWithOrientation: (UIInterfaceOrientation) io { UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"Default-%@.png", UIInterfaceOrientationName(io)]]; UIView *view = [[UIImageView alloc] initWithImage:img]; [view setFrame:[[UIScreen mainScreen] applicationFrame]]; return [view autorelease]; } - (void) loadView { self.view = [self startupImageWithOrientation:self.interfaceOrientation]; } - (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) io duration: (NSTimeInterval) duration { self.view = [self startupImageWithOrientation:io]; self.view.transform = CGAffineTransformFromUIOrientation(io); } 

有两个实用函数调用,你可以将它们填充到一个单独的文件中:

 NSString *UIInterfaceOrientationName(UIInterfaceOrientation io) { return UIInterfaceOrientationIsPortrait(io) ? @"Portrait" : @"Landscape"; } CGAffineTransform CGAffineTransformFromUIOrientation(UIInterfaceOrientation io) { assert(io <= 4); // unknown, portrait, portrait u/d, landscape L, landscape R static float angles[] = {0, 0, M_PI, M_PI/2, -M_PI/2}; return CGAffineTransformMakeRotation(angles[io]); } 

这有点乱,我自己也会对更简单的解决scheme感兴趣。

如果您locking了方向,则defult.png的分辨率可以影响您的应用程序方向。

例如,如果使用1024×768的飞溅图像,并且初始视图不支持通过方向locking进行纵向查看,则可能导致可视化UI对象出现在屏幕外(特别是在涉及animation时),因为视图将尝试以纵向方式呈现即使设备可能处于横向configuration。

一般来说,1024×768的图像意味着肖像,而768×1024的图像意味着风景。

如果这还不够,或者你想从最初的默认图像无缝地进入例如login屏幕,那么你可以使用视图控制器来“继续”飞溅。

加载所有正常的viewControllers到窗口,然后把你的'splash'viewController然后在你的splashController中使用shouldAutorotateToInterfaceOrientation方法来设置正确的图像(在ImageViewController上):

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Overriden to allow any orientation. switch ([[UIDevice currentDevice] orientation]) { case UIInterfaceOrientationLandscapeRight: splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default"] ofType:@"png"]]; break; case UIInterfaceOrientationPortrait: splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default"] ofType:@"png"]]; break; default: splashImage.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Default2"] ofType:@"png"]]; break; } return UIInterfaceOrientationIsLandscape(interfaceOrientation); } 

我使用的图像configuration可能不适合你,所以可能需要一些实验。

 - (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { // take action here , when phone is "Portrait" } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { action 4 LandscapeLeft } else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { //PortraitUpsideDown } else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { //LandscapeRight } 

注意你应该返回YES方法shouldAutorotateToInterfaceOrientation:

Interesting Posts