效果图:



注意:在 LaunchScreen.storyboard 中将 Storyboard ID 设置为 launch

如果需要设置启动页停留一段时间
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
[NSThread sleepForTimeInterval:3.0];//设置启动页面时间
return YES;
}
Swift代码
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
launchAnimation()
}
//播放启动画面动画
private func launchAnimation() {
//获取启动视图
let vc = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateViewControllerWithIdentifier("launch")
let launchview = vc.view
let delegate = UIApplication.sharedApplication().delegate
let mainWindow = delegate?.window
mainWindow!!.addSubview(launchview)
//播放动画效果,完毕后将其移除
UIView.animateWithDuration(1, delay: 0.5, options: .BeginFromCurrentState,
animations: {
launchview.alpha = 0.0
launchview.layer.transform = CATransform3DScale(CATransform3DIdentity, 1.5, 1.5, 1.0)
}) { (finished) in
launchview.removeFromSuperview()
}
}
}
OC代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self launchAnimation];
}
#pragma mark - Private Methods
- (void)launchAnimation {
UIViewController *viewController = [[UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil] instantiateViewControllerWithIdentifier:@"launch"];
UIView *launchView = viewController.view;
UIWindow *mainWindow = [UIApplication sharedApplication].keyWindow;
launchView.frame = [UIApplication sharedApplication].keyWindow.frame;
[mainWindow addSubview:launchView];
[UIView animateWithDuration:1.0f delay:0.5f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
launchView.alpha = 0.0f;
launchView.layer.transform = CATransform3DScale(CATransform3DIdentity, 2.0f, 2.0f, 1.0f);
} completion:^(BOOL finished) {
[launchView removeFromSuperview];
}];
}
@end
网友评论