iphone相关的闪屏
Posted
技术标签:
【中文标题】iphone相关的闪屏【英文标题】:Splash screen related in iphone 【发布时间】:2011-05-12 09:23:30 【问题描述】:您好,我正在尝试借助计时器来启动屏幕。但它不能。是否有关于此代码的任何建议.........
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
【问题讨论】:
你只有一张图片,所以没有必要拍摄动画,所以只需使用时间延迟我把你的解决方案放在下面 【参考方案1】:使用这个它可能是解决方案。
- (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];
祝你好运
【讨论】:
【参考方案2】:看起来你的 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 秒的淡入淡出动画后被调用。
【讨论】:
Thanx,但我试过还是不行,请给我一些建议。 你能告诉我们行为吗?它会褪色吗?它会在不褪色的情况下推送到主菜单吗?马上?【参考方案3】:你的代码泄露了:
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
【讨论】:
【参考方案4】:为什么不呢,在计时器到期并完成淡入淡出之后执行其他所有操作。
- (void) finishedFading
objMainMenuView = [[MainMenu alloc] initWithNibName:@"MainMenu" bundle:nil];
[self.navigationController pushViewController:objMainMenuView animated:YES];
【讨论】:
【参考方案5】:捷径:使用另一个带有 imageView 的 viewController 以模态方式呈现它并通过动画溶解关闭。 您应该在 viewWillAppear 中显示视图。在第二个 viewController 的 viewLoad 上启动计时器。当计时器触发时将其关闭。
【讨论】:
以上是关于iphone相关的闪屏的主要内容,如果未能解决你的问题,请参考以下文章