代码之家  ›  专栏  ›  技术社区  ›  sehugg

从iPhone默认位图淡入主应用程序

  •  1
  • sehugg  · 技术社区  · 15 年前

    执行渐变(0.5秒)的最简单/最快/最有效方法是什么 Default.png 到初始应用程序视图?

    我的初次尝试,效果不太好。现在是星期六晚上,我们看看能不能做得更好。)

    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];
    
    3 回复  |  直到 15 年前
        1
  •  1
  •   Stefan Arentz    15 年前

    如何:

    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与setAnimationDuration,未正确释放视图,并尝试将视图添加到self.view.frame而不是self.view。编译器应该捕获最后一个。这样做了吗?)

        2
  •  1
  •   joshrl    15 年前

    这是一个简单的视图控制器,它淡出默认图像并从视图层次中移除自身。这种方法的优点是,您可以在不修改现有视图控制器的情况下使用它…

    @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];
    } 
    
        3
  •  0
  •   David Kanarek    15 年前

    除了使用 setAnimationDelay: 而不是 setAnimationDuration: 看起来不错。你觉得结果怎么样?

    编辑:哇,使劲打。

    推荐文章