OK、アプリが起動したらすぐにを追加し、UIImageView
それをアニメーション化してスプラッシュアニメーションを偽造するという概念を理解しました。ただし、ステータスバーが干渉します。
ステータスバーを含め、すべての上にオンにする必要がありUIImageView
ます。フェードアウトしている間、アプリはステータスバーとともに表示されます。したがって、ステータスバーを最初に非表示にしてからアニメーション化することは、実行可能なオプションではありません。
OK、アプリが起動したらすぐにを追加し、UIImageView
それをアニメーション化してスプラッシュアニメーションを偽造するという概念を理解しました。ただし、ステータスバーが干渉します。
ステータスバーを含め、すべての上にオンにする必要がありUIImageView
ます。フェードアウトしている間、アプリはステータスバーとともに表示されます。したがって、ステータスバーを最初に非表示にしてからアニメーション化することは、実行可能なオプションではありません。
必要なのは、以上の秒UIWindow
です。アプリケーションデリゲートに2つのオブジェクトを作成します。1つは通常のビュー階層を使用し、もう1つは画像を使用して作成し、2番目のオブジェクトをアニメーション化してフェードアウトします(または、アニメーション化する必要があります)。スプラッシュウィンドウが上にある状態で、両方のウィンドウが表示されている必要があります。windowLevel
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]
アプリの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];
}];
}
}