0

好的,我得到了UIImageView应用程序一启动就添加 a 的概念,并对其进行动画处理以伪造启动动画。但是,状态栏会干扰。

我需要一个UIImageView最重要的东西,包括状态栏,当它消失时,应用程序会与状态栏一起显示。因此,将状态栏设置为最初隐藏,然后对其进行动画处理不是一个可行的选择。

4

2 回答 2

2

你需要的是一秒UIWindowwindowLevel更高UIWindowLevelStatusBar。您将在应用程序委托中创建两个UIWindow对象,一个具有常规视图层次结构,另一个具有图像,并为第二个设置动画以淡出(或者您需要设置动画)。两个窗口都应该可见,并且启动窗口位于顶部。

这种方法很复杂,因为您可能会遇到旋转问题,具体取决于您的常规视图层次结构。我们已经在我们的软件中做到了这一点,而且效果很好。


编辑:

适应解决方案(窗口方法,非常简单):

UIImageView* splashView = [[UIImageView alloc] initWithImage:[UIImage imageWithBaseName:@"Default"]];
[splashView sizeToFit];

UIViewController* tmpVC = [UIViewController new];
[tmpVC.view setFrame:splashView.bounds];
[tmpVC.view addSubview:splashView];

// just by instantiating a UIWindow, it is automatically added to the app.
UIWindow *keyWin = [UIApplication sharedApplication].keyWindow;
UIWindow *hudWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0.0f, -20.0f, keyWin.frame.size.width, keyWin.frame.size.height)];

[hudWindow setBackgroundColor:[UIColor clearColor]];
[hudWindow setRootViewController:tmpVC];
[hudWindow setAlpha: 1.0];
[hudWindow setWindowLevel:UIWindowLevelStatusBar+1];
[hudWindow setHidden:NO];

_hudWin = hudWindow;

[UIView animateWithDuration:2.3f animations:^{
    [_hudWin setAlpha:0.f];
} completion:^(BOOL finished) {
    [_hudWin removeFromSuperview];
    _hudWin = nil;
}];

最后,功劳归于这个家伙


更简单的方法是在隐藏状态栏的情况下启动您的应用程序,在视图层次结构的顶部放置您想要动画的视图,并在动画完成后,使用显示状态栏[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]

于 2013-01-12T18:03:55.353 回答
0

您可以将子视图添加到 App 的 UIWindow。将 UIImageView 框架的 Y 坐标设置为 -20 像素,以便处理状态栏。

将默认 PNG 图像添加到您的窗口并标记它:

static const NSInteger kCSSplashScreenTag = 420; // pick any number!
UIImageView *splashImageView;

// Careful, this wont work for iPad!
if ( [[UIScreen mainScreen] bounds].size.height > 480.0f ) // not best practice, but works for detecting iPhone5.
{
    splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default-568h"]];
}
else
{
    splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default"]];
}

splashImageView.frame = CGRectMake(0.0f, -20.0f, splashImageView.image.size.width, splashImageView.image.size.height);
splashImageView.tag = kCSSplashScreenTag;
[self.window addSubview:splashImageView];
[splashImageView release];

[self _fadeOutSplaceImageView];

然后淡出

- (void)_fadeOutSplashImageView
{
    UIView *splashview = [self.window viewWithTag:kCSSplashScreenTag];
    if ( splashview != nil )
    {
        [UIView animateWithDuration:0.5
                              delay:0.0
                            options:0
                         animations:^{
                             splashview.alpha = 0.0f;
                         }
                         completion:^(BOOL finished) {
                             [splashview removeFromSuperview];
                         }];
    }
}
于 2013-01-13T10:01:28.020 回答