[英]iOS: Animate splash screen out on top of status bar
好的,我得到了应用程序启动后立即添加UIImageView
的概念,并将其设置为动画以伪造启动动画。 但是,状态栏会干扰。
我需要在所有内容之上使用UIImageView
,包括状态栏,当它消失时,应用程序会显示状态栏。 因此,设置状态栏最初隐藏,然后设置动画不是一个可行的选项。
你需要的是第二个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;
}];
最后,归功于这个家伙 。
更简单的方法是在状态栏隐藏的情况下启动应用程序,在视图层次结构的顶部设置要设置动画的视图,动画完成后,使用[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]
显示状态栏[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide]
您可以将子视图添加到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];
}];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.