2010-01-24 60 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]; 
}