启动iOS应用程序时,屏幕从Default.png跳转到界面。对于当前的项目,我想从Default.png淡入到应用程序的界面。有没有好的方法可以做到这一点?
启动iOS应用程序时,屏幕从Default.png跳转到界面。对于当前的项目,我想从Default.png淡入到应用程序的界面。有没有好的方法可以做到这一点?
@interface DDViewController : UIViewController {
...
UIImageView *coverImageView;
}
...
@property (nonatomic, retain) UIImageView *coverImageView;
接下来,针对iPad应用的“主屏幕”,我调用以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
...
coverImageView = [[UIImageView alloc] init];
}
-(void)viewWillAppear:(BOOL)animated {
UIImage *defaultImage;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
NSLog(@"Landscape!");
defaultImage = [UIImage imageNamed:@"Default-Landscape.png"];
} else {
NSLog(@"Portrait!");
defaultImage = [UIImage imageNamed:@"Default-Portrait.png"];
}
coverImageView = [[UIImageView alloc] initWithImage:defaultImage];
[self.view addSubview:coverImageView];
}
-(void)viewDidAppear:(BOOL)animated {
//Remove the coverview with an animation
[UIView animateWithDuration:1.0f animations:^(void) {
[self.coverImageView setAlpha:0.0];
} completion:^(BOOL finished){
[coverImageView removeFromSuperview];
}];
}
这并不难做到。我通过创建一个带有默认图片的图像视图,并将其动画化来实现。类似这样(将其放入第一个视图控制器的viewDidLoad中):
_coverImage = [UIImage imageNamed:@"Default.png"];
}
[self.view addSubview:_coverImage];
[UIView beginAnimations:@"FadeOutCover" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(removeAndDeleteCover)];
[_coverImage setAlpha:0.0f];
[UIView commitAnimations];
[_coverImage removeFromSuperview];
有人在cocoacontrols.com上为它提供了一个控件
以下是它的链接: http://cocoacontrols.com/platforms/ios/controls/launchimagetransition
在rooster117的答案基础上,您需要在关闭“启动画面”视图控制器之前正确加载最终的“着陆点”,也就是您希望用户实际交互的视图控制器。这对于从网络加载数据的应用程序非常重要。