1
votes

Working on iphone splash screen, I have made custom animation with the help of some images that will be on my splash screen on landscape mode and then i want when my second view loads it should show up in portrait mode, but i am unable to implementing this, here goes my code:

@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);
}

I took one button in second view to remove the splash view from it, so as when we click the button on second view the splash view should go off, or same can be done on did load of second view but i am unable to achieve it

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

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

Note: I do not want to use the Default.png image for my flash i want this custom animation for my splash to be on landscape mode and following view's are in portrait, when i try to run this the second view comes up on the splash view but the splash view still appears on back of view .. i have only simulator to test .. can any one help me out on this??

4
A 15 second splash screen? I wouldn't be using your apps for sure.Richard J. Ross III
It will be only for Max 3 seconds.. it's just a sample code not the actual one.. lolzLion King
if you are in landscape mode in your splashcreen you probably want your second view in landscape but allow it to rotate in portrait no?tiguero

4 Answers

0
votes

Try using the following in viewDidLoad of that particular class

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] ;
0
votes

You could use the following code in your switchView method

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

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

appDelegate.window.rootViewController = sec;

}
0
votes
  • Try to present the second view instead of add subview because add subview does not call the shouldAutorotateToInterfaceOrientation method. It will definitely solve your problem.
0
votes

You shouldn't implement the switching of views within your spalshScreenController: that's is not its responsibility it is better to do it in your appdelegate applicationDidFinishLaunching method:

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

  }

and add a method that's respond to your button pressed what will present the view of your second controller.

-(void)onSlashScreenDone{

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

}

allow the orientation you want to allow in the secondcontroller by implementing the shouldAutorotateToInterfaceOrientation method.

Take a look to this tut: this is well explained about how to make a splashscreen on ios.