好的,我会在应用启动时立即添加UIImageView
的概念,并将其设置为动画以伪造启动动画。但是,状态栏会干扰。
我需要在所有内容之上UIImageView
,包括状态栏,当它消失时,应用程序会显示状态栏。因此,设置状态栏最初隐藏,然后设置动画不是一个可行的选项。
答案 0 :(得分:2)
您需要的是第二个UIWindow
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;
}];
最后,信用转到this guy。
更简单的方法是在隐藏状态栏的情况下启动应用程序,在视图层次结构的顶部设置要设置动画的视图,并在动画完成后使用{{1显示状态栏}}
答案 1 :(得分: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];
}];
}
}