Iphone Splash Screen挑战与Orientation

时间:2012-09-13 11:54:10

标签: iphone objective-c xcode

在iphone启动画面上工作,我已经在横向模式下我的启动画面上的一些图像的帮助下制作了自定义动画,然后我希望当我的第二个视图加载时它应该以纵向模式显示,但我是无法实现这一点,这里是我的代码:

@interface SplashViewController : UIViewController
 {
 IBOutlet   UIImageView *ani;
  NSMutableArray *arr;
}
@property(strong,nonatomic)UIImageView *ani; 
@property(strong,nonatomic)NSMutableArray *arr;
-(void)switchView;
@end

#import "SecondView.h"
@implementation SplashViewController
@synthesize ani,arr;  


 - (void)viewDidLoad
{

arr = [NSMutableArray arrayWithObjects:[UIImage imageNamed:@"image_1.png"],
       [UIImage imageNamed:@"image_2.png"],[UIImage imageNamed:@"image_3.png"], 
       [UIImage imageNamed:@"image_4.png"],[UIImage imageNamed:@"image_5.png"],
       [UIImage imageNamed:@"image_6.png"],[UIImage imageNamed:@"image_7.png"],
       [UIImage imageNamed:@"image_8.png"],[UIImage imageNamed:@"image_9.png"],
       [UIImage imageNamed:@"image_10.png"],[UIImage imageNamed:@"image_11.png"],
       [UIImage imageNamed:@"image_12.png"],[UIImage imageNamed:@"image_13.png"],
       [UIImage imageNamed:@"image_14.png"],[UIImage imageNamed:@"image_15.png"],
       [UIImage imageNamed:@"image_16.png"],[UIImage imageNamed:@"image_17.png"],
       [UIImage imageNamed:@"image_18.png"],[UIImage imageNamed:@"image_19.png"],       
         [UIImage imageNamed:@"image_20.png"],nil];


   [ani setImage:[UIImage imageNamed:@"image_20.png"]];

ani.animationImages=arr;

ani.animationDuration=10;
 //   ani.animationRepeatCount=1.0;
[ani startAnimating];
[self performSelector:@selector(switchView) withObject:nil afterDelay:15.0];


          [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.
}


-(void)switchView
{
 [ani stopAnimating];
 SecondView *sec=[[SecondView alloc]init];
[self.view addSubview:sec.view];

}

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

我在第二个视图中选择了一个按钮来删除它的启动视图,因此当我们单击第二个视图上的按钮时,启动视图应该关闭,或者在第二个视图的加载时也可以完成相同但我无法实现它

 -(IBAction)btn:(id)sender
{
 // UIViewController 
[self.view removeFromSuperview];
 }

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

注意:我不想为我的flash使用Default.png图像我希望我的自定义动画可以在横向模式下使用以下视图是纵向的,当我尝试运行此时第二个视图出现在飞溅视图但飞溅视图仍然出现在视图的背面..我只有模拟器来测试..任何人都可以帮我解决这个问题吗?

4 个答案:

答案 0 :(得分:0)

尝试在该特定类的viewDidLoad中使用以下内容

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] ;

答案 1 :(得分:0)

您可以在switchView方法中使用以下代码

-(void)switchView
{
 [ani stopAnimating];
 SecondView *sec=[[SecondView alloc]init];

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

appDelegate.window.rootViewController = sec;

}

答案 2 :(得分:0)

  • 尝试显示第二个视图而不是添加子视图,因为添加子视图不会调用shouldAutorotateToInterfaceOrientation方法。它肯定会解决你的问题。

答案 3 :(得分:0)

您不应该在spalshScreenController中实现视图切换:这不是它的责任,最好在appdelegate applicationDidFinishLaunching方法中执行:

-(void)applicationDidFinishLaunching:(UIApplication *)application {
     splashViewController = [[SplashViewController alloc] initWithNibName:@"SplashView" bundle:nil];
     [window addSubview:splashViewController.view];
     [window makeKeyAndVisible];

  }

并添加一个响应按钮的方法按下将显示第二个控制器的视图。

-(void)onSlashScreenDone{

     [splashViewController.view removeFromSuperview];
     [window addSubview:[youOtherController view]];
     [window makeKeyAndVisible];

}

通过实现shouldAutorotateToInterfaceOrientation方法,允许您在第二个控制器中允许的方向。

看看这个tut:关于如何在ios上制作启动画面的问题已经得到了很好的解释。