iphone 相关的启动画面

发布于 2024-11-06 16:44:09 字数 2296 浏览 0 评论 0原文

您好,我正在尝试借助计时器来启动屏幕。但它不能。关于此代码有任何建议吗......

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

过期以后 2024-11-13 16:44:09

使用这个它可能是解决方案。

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

}

祝你好运

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

隔纱相望 2024-11-13 16:44:09

看起来在您看到淡入淡出效果之前,您的 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 秒的淡入淡出动画后被调用。

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.

悲念泪 2024-11-13 16:44:09

你的代码泄露了:

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

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
三人与歌 2024-11-13 16:44:09

为什么不呢,在计时器到期并且褪色完成后执行其他操作。

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

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];
}
只想待在家 2024-11-13 16:44:09

快捷方式:使用另一个带有 imageView 的 viewController 以模态方式呈现它并通过动画溶解消除。
您应该在 viewWillAppear 中呈现视图。在第二个 viewController 的 viewLoad 上启动计时器。当计时器触发时将其关闭。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文