zoukankan      html  css  js  c++  java
  • 第五篇、Uber用视频播放做启动动画

    import UIKit
    import AVFoundation
    
    class GuidePage: FxBasePage {
    
        @IBOutlet var backImageView:UIImageView?
        
        var player:AVPlayer!
        var playerItem:AVPlayerItem!
        var location:FxLocation!
        
        override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?)
        {
            super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        convenience init ()
        {
            var nibNameOrNil = String?("GuidePage")
            
            //考虑到xib文件可能不存在或被删,故加入判断
            if NSBundle.mainBundle().pathForResource(nibNameOrNil, ofType: "nib") == nil {
                nibNameOrNil = nil
            }
            
            self.init(nibName: nibNameOrNil, bundle: nil)
        }
        
        override func viewDidLoad()
        {
            super.viewDidLoad()
            
            initPlayVideo()
            doAnimation()
        }
        
        override func didReceiveMemoryWarning()
        {
            super.didReceiveMemoryWarning()
        }
    
        func doAnimation()
        {
            var images:[UIImage]=[]
            var image:UIImage?
            var imageName:String?
            
            for var index=0; index<=67;index++ {
                imageName = "logo-" + String(format: "%03d", index)
                image = UIImage(named: imageName!)
                
                images.insert(image!, atIndex: index)
            }
            
            backImageView?.animationImages = images
            backImageView?.animationRepeatCount = 1
            backImageView?.animationDuration = 5
            
            backImageView?.startAnimating()
            
            UIView.animateWithDuration(0.7, delay:5, options: .CurveEaseOut, animations: {
                    self.backView!.alpha = 1.0
                    self.player?.play()
                }, completion: {
                    finished in
                    print("Animation End")
            })
        }
        
        func initPlayVideo ()
        {
            let path = NSBundle.mainBundle().pathForResource("welcome_video", ofType: "mp4")
            let url = NSURL.fileURLWithPath(path!)
            
            playerItem = AVPlayerItem(URL: url)
            player = AVPlayer(playerItem: playerItem)
            
            let playerLayer = AVPlayerLayer(player: player)
            
            playerLayer.frame = backView!.bounds
            playerLayer.videoGravity =  AVLayerVideoGravityResizeAspect
            
            backView!.layer.insertSublayer(playerLayer, atIndex: 0)
            backView!.alpha = 0.0
            
            NSNotificationCenter.defaultCenter().addObserver ( self,
                selector: "didFinishVideo:" ,
                name: AVPlayerItemDidPlayToEndTimeNotification ,
                object: playerItem)
        }
        
      // 播放到视频结尾之后,要重新开放播放 func didFinishVideo(sender: NSNotification ) { let item
    = sender.object as! AVPlayerItem item.seekToTime(kCMTimeZero) self.player.play() }
      // 跳转登录 @IBAction func doLogin() { location
    = FxLocation() location.startLocation() }
      // 跳转注册 @IBAction func doRegister() { let page
    = CreateAccountPage() let navPage = UINavigationController(rootViewController: page) self.presentViewController(navPage, animated: true, completion: nil) } }
  • 相关阅读:
    ASP.NET Core2利用MassTransit集成RabbitMQ
    ASP.NET Core2集成Office Online Server(OWAS)实现办公文档的在线预览与编辑(支持wordexcelpptpdf等格式)
    ASP.NET Core2利用Jwt技术在服务端实现对客户端的身份认证
    net core System.Drawing is not supported on this platform.
    小程序开发之维护access_token
    net core 100个案例
    msgSystem.Drawing is not supported on this platform【netcore】
    wpf,前端动画demo,鱼眼效果
    自定义控件,重写 TextBox 实例
    TextBox输入法控制,进入输入框则启用或禁用输入法(ime),禁用后只能输入英文
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/5880018.html
Copyright © 2011-2022 走看看