美文网首页
通过LaunchScreen实现启动页放大淡出的动画效果_Swi

通过LaunchScreen实现启动页放大淡出的动画效果_Swi

作者: YHWXQ简简单单的生活 | 来源:发表于2016-09-02 18:31 被阅读1005次

效果图:

Paste_Image.png Paste_Image.png

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

Paste_Image.png
如果需要设置启动页停留一段时间
- (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

相关文章

网友评论

      本文标题:通过LaunchScreen实现启动页放大淡出的动画效果_Swi

      本文链接:https://www.haomeiwen.com/subject/stckettx.html