I need to implement animated splash screen to the iPhone application. I have seen skype application where same thing is already implemented.
Can anyone has idea how can i implement same thing in my applicatio
You can use sequence of images, here is code :
for(NSInteger i=1;i<=totalImages;i++){
NSString *strImage = [NSString stringWithFormat:#"Activity_%d",i];
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:strImage ofType:#"png"]];
[imageArray addObject:image];
}
splashImageView.animationImages = imageArray;
splashImageView.animationDuration = 0.8;
and just call startAnimation and endAnimation method of UIImageView.
OR
Its very simple...I had used it in to begin my app with splashView.Hope it vil help you.... In AppDelegate.m:
application didFinishLaunchingWithOptions:
UIImage* image=[UIImage imageNamed:#"splash.jpg"];
splashView=[[UIImageView alloc]initWithImage:image];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:self afterDelay:2];
[window makeKeyAndVisible];
To remove splashView:
-(void)removeSplash{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[splashView removeFromSuperview];
[UIView commitAnimations];
[window addSubview:viewController.view];
}
We can show a .gif image in webView and it looks perfect!
Take a new UIViewController class named SplashView with XIB and then add an UIWebView with (320.0, 480.0) frame, hidden statusbar also.
In SplashView.h
#import <UIKit/UIKit.h>
#interface SplashView : UIViewController
#property(nonatomic, retain)IBOutlet UIWebView *webView;
#end
In SplashView.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *imagePath = [[NSBundle mainBundle] pathForResource: #"animated" ofType: #"gif"];
NSData *data = [NSData dataWithContentsOfFile:imagePath];
[self.webView setUserInteractionEnabled:NO];
[self.webView loadData:data MIMEType:#"image/gif" textEncodingName:nil baseURL:nil];
}
This is about SplashView class. Now come to your appdelegate's class.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
splashView = [[SplashView alloc]initWithNibName:#"SplashView" bundle:nil];
[self.window addSubview:splashView.view];
[self performSelector:#selector(changeView) withObject:nil afterDelay:3.0];
[self.window makeKeyAndVisible];
return YES;
}
-(void)changeView
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[splashView.view removeFromSuperview];
[self.window setRootViewController:self.viewController];
}
Take a UIView & an Imageview into it. Give all your images to ImageView to animate.
-(void)viewDidLoad
{
NSArray *arrImage=[NSArray arrayWithObjects:
[UIImage imageNamed:#"1.png"],
[UIImage imageNamed:#"2.png"],
[UIImage imageNamed:#"3.png"],
nil];
imgVw.backgroundColor=[UIColor purpleColor];
imgVw.animationImages=arrImage;
imgVw.animationDuration=2.5;
imgVw.animationRepeatCount=1;
[imgVw startAnimating];
[NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:#selector(animateNext) userInfo:nil repeats:NO];
}
This will show up you application icon.
After that you will show the controls those would be hidden by default and animate them from bottom to up.
-(void)animateNext
{
lbl.hidden = NO;
btn.hidden = NO;
txt1.hidden = NO;
txt2.hidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.9];
lbl.frame=CGRectMake(lbl.frame.origin.x,lbl.frame.origin.y - 150,lbl.frame.size.width,lbl.frame.size.height);
imgVw.frame = CGRectMake(imgVw.frame.origin.x, imgVw.frame.origin.y - 150, imgVw.frame.size.width, imgVw.frame.size.height);
txt1.frame = CGRectMake(txt1.frame.origin.x, txt1.frame.origin.y - 150, txt1.frame.size.width, txt1.frame.size.height);
txt2.frame = CGRectMake(txt2.frame.origin.x, txt2.frame.origin.y - 150, txt2.frame.size.width, txt2.frame.size.height);
btn.frame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y - 150, btn.frame.size.width, btn.frame.size.height);
[UIView commitAnimations];
}
Hope this help...
Try this
Appdelegate.h
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIImageView *splashView;
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
// Make this interesting.
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default.png"];
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
splashView.frame = CGRectMake(-60, -85, 440, 635);
[UIView commitAnimations];
return YES;
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[splashView removeFromSuperview];
}
you need to start your app with a viewcontroller,with an uiimageview in it..Create a series of .png images to be subjected to the UIImageView check how to animate array of images in uiimageview. Further to dismiss it once animation over you would need to implement a protocol that will inform your starting first viewcontroller of your app to dismiss the animation
- (void) welcomeScreen
{
//Welcome Screen
UIImageView* welcome = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)]autorelease];
welcome.image = [UIImage imageNamed:#"img.png"];
[window addSubview:welcome];
[window bringSubviewToFront:welcome];
//Animation Effects (zoom and fade)
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:welcome];
[UIView setAnimationDidStopSelector:#selector(removeFromSuperview)];
//set transparency to 0.0
welcome.alpha = 0.0;
//zoom effect
welcome.frame = CGRectMake(-60, -60, 440, 600);
[UIView commitAnimations];
}
yes simple in AppDelegate class first defile imageview like bellow..
#interface AppDelegate : UIResponder
{
UIImageView *splashView;
}
and in .m file...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"Default"];
[self.window addSubview:splashView];
[self performSelector:#selector(loadViewIphone) withObject:nil afterDelay:2.0];
}
[self.window makeKeyAndVisible];
return YES;
}
-(void)loadViewIphone
{
[splashView removeFromSuperview];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:#"transitionViewAnimation"];
}
i hope this help you..
:)
Related
I am trying to replicate the screen in the middle, namely the alert that is displayed to compose a new tweet. I have tried to duplicate it with a custom UIAlertView but that requires a lot of subclassing and what not, then I suspected it might just be a simple UIViewController that is displayed over the main view... professional thoughts from fellow iOS developers is needed.
Thank you.
In iPad:
You can do it with a UIViewController.
You need to design UI according to the above image.
Then you need to set the Modal Presentation Style to UIModalPresentationFormSheet
And present it using - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))
Like:
UIViewController *viewC = [[UIViewController alloc] init];
viewC.view.frame = //set the frame;
viewC.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:viewC animated:YES completion:nil];
In iPhone:
You can do it with using a UIView.
You can use the following code for doing this:
Declare a property in your interface
#property (nonatomic, strong) UIView *views;
//Add the view
- (void) showView
{
UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 35)];
UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(remove)];
toolbar.items = [NSArray arrayWithObject:bar];
_views = [[UIView alloc] initWithFrame:CGRectMake(0, -300, self.view.bounds.size.width, self.view.bounds.size.height/3)];
[_views addSubview:toolbar];
[_views setBackgroundColor:[UIColor grayColor]];
[self.view addSubview:_views];
[UIView animateWithDuration:0.7
delay:0.0
options:UIViewAnimationCurveLinear
animations:^{
_views.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height/3);
}
completion:^(BOOL yes){
NSLog(#"YO");
}];
[UIView commitAnimations];
}
//Remove the view
- (void)remove
{
[UIView animateWithDuration:0.7
delay:0.0
options:UIViewAnimationCurveLinear
animations:^{
_views.frame = CGRectMake(0, -500, self.view.bounds.size.width, self.view.bounds.size.height/3);
}
completion:^(BOOL yes){
NSLog(#"YA");
}];
[UIView commitAnimations];
}
I am getting an different image at the start of the app like a splash screen then i am getting my actual image that i placed in coding.
I placed the splash screen with the following code in my didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.tabBarController;
self.tabBarController.delegate=self;
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
LoginViewController *vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
self.loginNav = [[UINavigationController alloc] initWithRootViewController:vc];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults valueForKey:#"UserName"] &&[userDefaults valueForKey:#"Password"])
{
vc.username=[userDefaults valueForKey:#"UserName"];
vc.password=[userDefaults valueForKey:#"Password"];
vc.autoLogin=YES;
[vc loginSelectorMethod];
}
else
{
[self.window addSubview:self.loginNav.view];
[self.window makeKeyAndVisible];
}
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:3.0];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(#"Registering for remote notifications");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
Before the splash screen appears , the "Arrow.png" image appears then my splash screen appers.
If i delete the "Arrow.png" then in place of that image another images appears i.e., "aboutus.png" like that it continues.
I searched in my project for the "Arrow.png" it only appears once in my whole project in the coding.
here you add subiview as a tabbar like bellow..
[window addSubview:tabBarController.view];
after you add loginview like bellow..
[self.window addSubview:self.loginNav.view];
and after that you add splashscreen like bellow..
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
So this is the problem that you seen more then screen instead of splashscreen.
use bellow code...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:#"splashscreen.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:#selector(removeSplash) withObject:nil afterDelay:3.0];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
NSLog(#"Registering for remote notifications");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
and in removeSplash method add this view as a subview of window like bellow..
-(void)removeSplash{
[splashView removeFromSuperView];
LoginViewController *vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
self.loginNav = [[UINavigationController alloc] initWithRootViewController:vc];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults valueForKey:#"UserName"] &&[userDefaults valueForKey:#"Password"])
{
vc.username=[userDefaults valueForKey:#"UserName"];
vc.password=[userDefaults valueForKey:#"Password"];
vc.autoLogin=YES;
[vc loginSelectorMethod];
}
else
{
[self.window addSubview:self.loginNav.view];
[self.window makeKeyAndVisible];
}
}
Have you set any Launch image in ur project setting or have you put any image named "Default.png" in your project bundle this kind of image get detect by OS automatically while launch our app please check this 2 points.
edit:-
Than the problem is conflict in TabBar & LoginView & splaceImage.
For this do below stuff I thing this resolve your double image issue.
First, put below code in your DidFinishLaunching() method
//Delay second that how much time u show your splace image
int64_t delayInSeconds = 5.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//Do need Full like Add Login View or Add TabbBar
//Remove SplaceImageView From Window
});
splashView = [[UIImageView alloc] initWithFrame:self.window.frame];
splashView.image = [UIImage imageNamed:#"Default-Portrait~ipad.png"];
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
return YES;
and also one more thing add default splace image like
for iPhone Portrait Default.png.
for iPad, Portrait Default-Portrait~ipad.png
follow as apple document for default image and then check.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.sql_ = [SQLDb initEngine];
[self setupControllers]; /// Set up Yor ToolBar Controller
self.hvController = [[HomeViewController alloc] init];
self.window.rootViewController = self.hvController;
[self.window makeKeyAndVisible];
[self setupSplash];
return YES;
}
-(void) setupSplash
{
self.imvSplash = [[UIImageView alloc] initWithFrame:self.window.bounds];
if( IS_IPHONE_5 )
[self.imvSplash setImage: [UIImage imageNamed:#"Default-568h#2x.png"]];
else
[self.imvSplash setImage: [UIImage imageNamed:#"splash.png"]];
[self.window addSubview: self.imvSplash];
[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:#selector(hideSplash:) userInfo:nil repeats:NO];
}
- (void)hideSplash:(NSTimer *)theTimer
{
[UIView animateWithDuration:1.0
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
self.imvSplash.alpha = 0.0;
self.ngNavigationController.view.alpha = 1.0;
}
completion:^(BOOL finished)
{
//[self.ngController setupImageAction];
[self.imvSplash removeFromSuperview];
}];
}
How do I add UISplitView after clicking on the SingleView application? Clearly when the user has successfully logged in then they will see splitView? How is it possible? Please give me guidelines or if possible then code for that because I'm new to iPhone development and I haven't more knowledge for it?
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.90];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.navigationController.view cache:YES];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
if (!masternavigationController) {
masternavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
}
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
if (!splitViewController) {
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:masternavigationController, detailViewController, nil];
UIViewController *view_controller = (UIViewController *)[navigationController.viewControllers objectAtIndex:([navigationController.viewControllers count]-1)];
[masternavigationController.navigationBar setHidden:TRUE];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[splitViewController.view setBounds:CGRectMake(0, 0, 1024, 748)];
[splitViewController.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[view_controller.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
view_controller.view.tag = 17;
[UIView animateWithDuration:1.05 animations:^{navigationController.view.alpha = 0.0;} completion:^(BOOL finished){
[navigationController.view addSubview:splitViewController.view];
[UIView animateWithDuration:1.00 animations:^{navigationController.view.alpha = 1.0;} completion:nil];}];
rootview *rtview = [[rootview alloc] initWithNibName:#"rootview" bundle:nil];
rtview.delegate = detailViewController;
[detailViewController.view addSubview:rtview.view];
flag = YES;
[rtview release];
}
[UIView commitAnimations];
// [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:#selector(doneAnimation) userInfo:nil repeats:NO];
[masterViewController release];
[detailViewController release];
This is how we have to add splitview controler you have to check the condition weather you are logged in or not and then call this in a method
I am wanting to animate my view change, however I am not sure where to put my animation since I have a UITabBarController controlling which view I am on and what I can switch too.. This is being declared in my appdelegate.m file as per the xcode template.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Or their is the area in each viewcontroller where everything gets loaded... Im thinking it might be better to initialize the animation in here.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(#"Super", #"Super");
self.tabBarItem.image = [UIImage imageNamed:#"SuperIcon"];
}
return self;
}
As I have not done alot of animation with views before I am woundering where I could declare this peice of code that will hopefully animate my view change when a UITabBarButton is touched....
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView];
completion:NULL];
or have I missed the boat completely and is their somewhere else I should be doing this?
Try the following code in the viewWillAppear method
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView commitAnimations];
This worked for me for a tabBar controller based app.
Try that animation in code in viewWillAppear method
Hi I am trying to splash screen with the help of timer. but it can't. IS any suggestion regarding this code.........
SplashViewController.h:-
#import <UIKit/UIKit.h>
#import "MainMenu.h"
#interface SplashViewController : UIViewController {
UIImage *imgSplash;
NSTimer *timer;
MainMenu *objMainMenuView;
}
#property (nonatomic,retain) NSTimer *timer;
#property (nonatomic,retain) UIImage *imgSplash;
#property (nonatomic,retain) MainMenu *objMainMenuView;
#end
SplashViewController.m:-
#import "SplashViewController.h"
#implementation SplashViewController
#synthesize timer,imgSplash,objMainMenuView;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
timer = [[NSTimer alloc] init];
UIImageView *splashImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];
imgSplash = [[UIImage alloc] init];
imgSplash = [UIImage imageNamed:#"chicocredit_splash.png"];
[splashImageView setImage:imgSplash];
[self.view addSubview:splashImageView];
timer = [NSTimer timerWithTimeInterval:2.0 target:self.timer selector:#selector(fadeScreen) userInfo:nil repeats:NO];
if([timer isValid]==1)
{
[timer fire];
//self.view.alpha = 0.0;
objMainMenuView = [[MainMenu alloc] initWithNibName:#"MainMenu" bundle:nil];
[self.navigationController pushViewController:objMainMenuView animated:YES];
}
}
-(void) onTimer{
NSLog(#"LOAD");
}
- (void)fadeScreen
{
[UIImageView beginAnimations:nil context:nil];
[UIImageView setAnimationDuration:2.0];
[UIImageView setAnimationDelegate:self];
[UIImageView commitAnimations];
//[UIView setAnimationDidStopSelector:#selector(finishedFading)];
//self.view.alpha = 0.0;
//[UIView commitAnimations];
}
/*
- (void) finishedFading
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
//self.view.alpha = 1.0;
//viewController.view.alpha = 1.0;
//self.objMainMenuView.view.alpha = 1.0;
[UIView commitAnimations];
//[splashImageView removeFromSuperview];
}*/
- (void)dealloc {
[super dealloc];
}
#end
Use this It may be solution for that.
- (void)viewDidLoad {
timer = [[NSTimer alloc] init];
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 460.0f);
splashImageView = [[UIImageView alloc] initWithFrame:myImageRect];
[splashImageView setImage:[UIImage imageNamed:#"image3.jpg"]];
splashImageView.opaque = YES;
[self.view addSubview:splashImageView];
[splashImageView release];
[self performSelector:#selector(doTHis) withObject:nil afterDelay:2.0];
[super viewDidLoad];
}
-(void)doTHis{
objMainMenuView = [[MainMenu alloc] initWithNibName:#"MainMenu" bundle:nil];
[self.navigationController pushViewController:objMainMenuView animated:YES];
}
Good Luck
Looks like your MianMenu is getting pushed before you can see the fade effect. Its because you are firing the timer and pushing the Main Menu immediately.
// Schedule the timer here.
[NSTimer timerWithTimeInterval:2.0f target:self selector:#selector(timerFireMethod:) userInfo:nil repeats:NO];
// Timer fire method.
-(void) timerFireMethod:(NSTimer *) theTimer {
[UIView beginAnimations:nil context: nil];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: #selector(animationDidStop: finished: context:)];
// Put animation code.
[UIView commitAnimations];
}
// Called when animation finishes.
-(void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
// Called when animation finishes.
// Push the Main menu here.
}
Keep break point in the timer fire method. It should get called after 2 seconds as specified.
Then keep break point in the animationDidStopSelector method. It will get called after your fade animation of 2 seconds.
Your code is leaked:
1:
timer = [[NSTimer alloc] init]; //Leak here, remove this line
.
.
.
timer = [NSTimer timerWithTimeInterval:2.0 target:self.timer selector:#selector(fadeScreen) userInfo:nil repeats:NO];
2:
imgSplash = [[UIImage alloc] init];//Leak here, remove this line
imgSplash = [UIImage imageNamed:#"chicocredit_splash.png"];
3:
UIImageView *splashImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];
...
[splashImageView setImage:imgSplash]; //Leak here, should release splashImageView
Why not, do everything else after timer expired and fading is done.
- (void) finishedFading
{
objMainMenuView = [[MainMenu alloc] initWithNibName:#"MainMenu" bundle:nil];
[self.navigationController pushViewController:objMainMenuView animated:YES];
}
short cut: use another viewController with imageView present it modally and dismiss with animation dissolve.
You should present view in viewWillAppear.Start timer on viewLoad of second viewController.When timer fires dismiss it.