2011-05-12 65 views
1

嗨,我试图在定时器的帮助下启动屏幕。但它不能。是关于这个代码的任何建议.........iPhone中相关的初始屏幕

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 
+0

你刚才单一的形象所以它不是必要采取动画,以便只使用时间延迟,我把你的解决方案在下面 – sinh99 2011-05-13 05:27:32

回答

2

使用此可能是解决方案。

- (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]; 

}

好运

1

看起来你在看到褪色效果之前,MianMenu已经被推上了。因为你正在触发定时器并立即推动主菜单。

//在此安排计时器。

[NSTimer timerWithTimeInterval:2.0f target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:NO]; 

//定时器启动方法。

-(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]; 

}

//时调用动画完成。

-(void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
// Called when animation finishes. 
// Push the Main menu here. 
} 

在计时器火法中保持断点。它应该在指定的2秒后被调用。 然后在animationDidStopSelector方法中保留断点。它会在2秒的淡出动画后被调用。

+0

感谢名单,但我想它仍然不工作PLZ给我一些建议。 – 2011-05-12 10:34:45

+0

你能告诉我们这个行为吗?它会褪色吗?它是否推向主菜单而不会退色?立即? – 2011-05-12 10:57:44

0

您的代码泄露:

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 
+0

雅我已经删除,但仍然无法正常工作 – 2011-05-12 10:34:27

0

不为什么,做一切之后计时器到期,淡化完成。

- (void) finishedFading 
{ 
     objMainMenuView = [[MainMenu alloc] initWithNibName:@"MainMenu" bundle:nil]; 
     [self.navigationController pushViewController:objMainMenuView animated:YES]; 
} 
0

捷径:使用其他的viewController与ImageView的模态呈现,并驳回动画溶解。
你应该在viewWillAppear.Start定时器的viewLoad第二个viewController.When定时器发射解雇它。