2011-05-12 4 views
1

안녕하세요, 저는 타이머를 사용하여 화면을 스플래시하려고합니다. 하지만 그렇게 할 수는 없습니다. 이 코드에 대한 어떤 제안이 .........아이폰에 스플래시 화면 관련

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

답변

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이 나에게 약간의 제안을하고 있습니다. –

+0

우리에게 그 행동을 말할 수 있습니까? 그것은 퇴색 하는가? 페이딩없이 메인 메뉴로 이동합니까?그리고 즉시? –

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

나중에 삭제했지만 여전히 작동하지 않습니다. –

0

왜, 다른 모든 것을 할 및 페이딩이 수행됩니다.

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

바로 가기 : 용해 애니메이션 모달을 제시하고 해고 이미지 뷰와 다른의 ViewController를 사용합니다.
viewWillAppear에서 뷰를 제공해야합니다. 두 번째 viewController의 viewLoad에 타이머를 시작해야합니다. 타이머가 종료되면 타이머가 종료됩니다.