美文网首页
iOS 启动页动画OC+Swift

iOS 启动页动画OC+Swift

作者: _Waiting_ | 来源:发表于2018-06-14 09:48 被阅读28次

原理是在keywindow上加一个imgeview:demo
OC 代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[ViewController alloc] init];
    [self.window makeKeyAndVisible];
    [self customLaunchImageView];
    return YES;
}

- (void)customLaunchImageView
    {
        UIImageView *launchImageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
        launchImageView.image = [UIImage imageNamed:@"launchScreen_bg"];
        [self.window addSubview:launchImageView];
        [self.window bringSubviewToFront:launchImageView];
        
        
        UIImageView *img1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width * 0.7, [UIScreen mainScreen].bounds.size.width * 0.7)];
        img1.center = CGPointMake(self.window.center.x,[UIScreen mainScreen].bounds.size.height *0.36);
        img1.image = [UIImage imageNamed:@"launchScreen_b"];
        [launchImageView addSubview:img1];
        [self addAnimation:img1 cc:NO];
        
        UIImageView *img2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width * 0.7, [UIScreen mainScreen].bounds.size.width * 0.7)];
        img2.center = CGPointMake(self.window.center.x,[UIScreen mainScreen].bounds.size.height *0.36);
        img2.image = [UIImage imageNamed:@"launchScreen_c"];
        [launchImageView addSubview:img2];
        [self addAnimation:img2 cc:YES];
        
 

        
        
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:1.2 animations:^{

            } completion:^(BOOL finished) {
                [launchImageView removeFromSuperview];
                //do something
            }];
        });
    }
- (void)addAnimation:(UIView *)view cc:(BOOL)cc
    {
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        if (cc)
        {
            animation.fromValue = [NSNumber numberWithFloat:0.f];
            animation.toValue = [NSNumber numberWithFloat: M_PI *2];
        }
        else
        {
            animation.fromValue = [NSNumber numberWithFloat: M_PI *2];
            animation.toValue = [NSNumber numberWithFloat:0.f];
        }
        
        animation.duration = 3;
        animation.autoreverses = NO;
        animation.fillMode = kCAFillModeForwards;
        animation.repeatCount = MAXFLOAT;
        [view.layer addAnimation:animation forKey:nil];
    }

SWift代码

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        self.window?.makeKeyAndVisible()
        
        let launchImageView = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
        launchImageView.image = UIImage.init(named: "launchScreen_bg")
        launchImageView.backgroundColor = UIColor.red
        self.window?.addSubview(launchImageView)
        self.window?.bringSubview(toFront: launchImageView)
        
        
        let img_b = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width * 0.7, height: UIScreen.main.bounds.size.width * 0.7))
        img_b.center = CGPoint.init(x: (self.window?.center.x)!, y: UIScreen.main.bounds.size.height * 0.36)
        img_b.image = UIImage.init(named: "launchScreen_b")
        launchImageView.addSubview(img_b)
        self.addAnimation(view: img_b, isOrder: false)
        
        let img_c = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width * 0.7, height: UIScreen.main.bounds.size.width * 0.7))
        img_c.center = CGPoint.init(x: (self.window?.center.x)!, y: UIScreen.main.bounds.size.height * 0.36)
        img_c.image = UIImage.init(named: "launchScreen_c")
        launchImageView.addSubview(img_c)
        self.addAnimation(view: img_c, isOrder: true)
        
        
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            
            UIView.animate(withDuration: 0.5, animations: {
                
            }, completion: { (finished:Bool) in
                
                launchImageView.removeFromSuperview()
                // do something
  
                
            })
            
        }
        
        return true
    }

    func addAnimation(view:UIView,isOrder:Bool)
    {
        let animation = CABasicAnimation.init(keyPath: "transform.rotation.z")
        if isOrder {
            animation.fromValue = 0.0
            animation.toValue = Double.pi * 2
        }
        else
        {
            animation.fromValue = Double.pi * 2
            animation.toValue = 0.0
        }
        animation.duration = 4
        animation.autoreverses = false
        animation.fillMode = kCAFillModeForwards
        animation.repeatCount = 2
        view.layer.add(animation, forKey: nil)
    }

相关文章

  • iOS 启动页动画OC+Swift

    原理是在keywindow上加一个imgeview:demoOC 代码 SWift代码

  • iOS适配启动页

    iOS适配启动页 iOS适配启动页

  • iOS 延迟启动页以及启动页动画

    1、单纯的延长启动页 2、启动页动画

  • iOS代码添加视图约束

    项目要做这样一个效果的启动页。 考虑到版本号是会不断变更的,因此采用动画效果启动页,让版本号动态加载iOS启动页动...

  • iOS开发_启动页动画

    【作者前言】:13年入圈,分享些本人工作中遇到的点点滴滴那些事儿,17年刚开始写博客,高手勿喷!以分享交流为主,欢...

  • iOS 启动页带动画

    APP在启动的时候有的是静态图有的是动图,那怎么设置动图呢?本文主要介绍从网络上获取动图,这样可以只更改服务器上的...

  • iOS启动页动画效果

    最近项目中要在启动页增加版本号,因为版本号是不断的改变,所以要动态实现把它加到启动页上;在XCode上面配置的La...

  • 实现点赞的动画及播放起伏指示器(OC+Swift)

    实现点赞的动画及播放起伏指示器(OC+Swift) 实现点赞的动画及播放起伏指示器(OC+Swift)

  • Flutter 启动页

    启动页 IOS启动页,在ios/Runner/Assets.xcassets/LaunchImage.images...

  • [iOS]Swift-启动页动画

    从开发者角度讲app启动当然越快越好,但是有时候总有些奇葩需求。比如,让启动页故意延时、在启动页上加个动画等等。下...

网友评论

      本文标题:iOS 启动页动画OC+Swift

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