2010-01-24 27 views
1

执行从Default.png到初始应用程序视图的逐渐(0.5秒)淡出的最简单/最快/最有效的方式是什么?从iPhone默认位图淡入主应用程序

我最初的尝试,它不工作这么好..它是星期六晚上,让我们看看我们是否能够比使用setAnimationDelay:代替setAnimationDuration:做的更好:)

UIImageView* whiteoutView = [[UIImageView alloc] initWithFrame:self.view.frame]; // dealloc this later ?? 
whiteoutView.image = [UIImage imageNamed:@"Default.png"]; 
whiteoutView.alpha = 1.0; 
[self.view.frame addSubview:whiteoutView]; 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDelay:0.5]; 
whiteoutView.alpha = 0; 
[UIView commitAnimations]; 

回答

1

什么:

UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.view.frame] autorelease]; 
if (whiteoutView != nil) 
{ 
    whiteoutView.image = [UIImage imageNamed:@"Default.png"]; 
    [self.view addSubview:whiteoutView]; 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration: 0.5]; 
    whiteoutView.alpha = 0.0; 
    [UIView commitAnimations]; 
} 

(的东西,你有错的是setAnimationDelay VS setAnimationDuration,不能正常释放视图,并尝试添加到self.view.frame代替self.view视图中的编译器。应该抓住那最后一个吧?)

+0

作品,除了在我的情况下,我有一个UITabBarController,必须做'[self tabBarController] .view'而不是'self.view'。作品! – sehugg 2010-01-24 05:46:19

0

其他,它看起来相当不错。关于结果你不喜欢什么?

编辑:哇难打。

1

下面是一个简单的视图控制器,它可以淡出默认图像并从视图层次结构中删除它自己。这种方法的好处是,你可以使用这个,而无需修改现有的视图控制器...

@interface LaunchImageTransitionController : UIViewController {} 
@end 
@implementation LaunchImageTransitionController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]] autorelease]; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:.5]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(imageDidFadeOut:finished:context:)]; 
    self.view.alpha = 0.0; 
    [UIView commitAnimations]; 

} 
- (void)imageDidFadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    [self.view removeFromSuperview]; 
    //NOTE: This controller will automatically be released sometime after its view is removed from it' superview... 
} 
@end 

这里是如何使用它在你的应用程序代理:

- (void)applicationDidFinishLaunching:(UIApplication *)application {  

    //create your root view controller, etc... 
    UIViewController *rootController = .... 

    LaunchImageTransitionController *launchImgController = [[[LaunchImageTransitionController alloc] init] autorelease]; 

    [window addSubview:rootController.view]; 
    [window addSubview:launchImgController.view]; 

    [window makeKeyAndVisible]; 
}