当我使用下面提到的代码时,我会在iPhone模拟器上获得所需的淡出淡出屏幕,但是图片似乎是用因子2缩放的:我只得到我初始图片的左上角(=启动)图像),缩放到全屏。在启动画面启动之前,启动图像本身在启动时以正确的大小显示。
在AppDelegate的didFinishLaunchingWithOptions中输入代码。
// Splash screen
UIImageView*imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"IMG_1357.png"]];
[[navigationController view] addSubview:imageView];
[[navigationController view] bringSubviewToFront:imageView];
// as usual
[self.window makeKeyAndVisible];
//now fade out splash image
[UIView transitionWithView:self.window duration:4.0f options:UIViewAnimationOptionTransitionNone animations:^(void){imageView.alpha=0.0f;} completion:^(BOOL finished){[imageView removeFromSuperview];}];
此外,启动画面似乎没有出现在设备上(iOS 4的iPhone 4S(Retina)),仅在模拟器上:在iPhone上运行时,它只显示启动图像。
这两个问题的原因和解决方案是什么? 提前谢谢!
答案 0 :(得分:2)
示例:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IMG_1357.png"]];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.frame = self.window.bounds;
[self.window addSubview:imageView];
[imageView release];
[self.window makeKeyAndVisible];
//now fade out splash image
[UIView transitionWithView:self.window
duration:4.0f
options:UIViewAnimationOptionTransitionNone
animations:^(void) {
imageView.alpha = 0.0f;
}
completion:^(BOOL finished ){
[imageView removeFromSuperview];
}];
在淡出前添加1秒暂停:
int64_t delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[UIView transitionWithView:self.window
duration:4.0f
options:UIViewAnimationOptionTransitionNone
animations:^(void) {
imageView.alpha=0.0f;
}
completion:^(BOOL finished ){
[imageView removeFromSuperview];
}];
});
或
[self performSelector:@selector(_hideSplash:) withObject:imageView afterDelay:1.0];
- (void) _hideSplash:(UIView *)view
{
[UIView transitionWithView:self.window
duration:4.0f
options:UIViewAnimationOptionTransitionNone
animations:^(void) {
view.alpha=0.0f;
}
completion:^(BOOL finished ){
[view removeFromSuperview];
}];
}