Guest User

Untitled

a guest
Feb 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. import UIKit
  2. import AVFoundation
  3.  
  4. @UIApplicationMain
  5. class AppDelegate: UIResponder, UIApplicationDelegate {
  6.  
  7. var window: UIWindow?
  8. var audioPlayer = AVAudioPlayer()
  9.  
  10. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  11. // Override point for customization after application launch.
  12.  
  13. self.window = UIWindow(frame: UIScreen.main.bounds)
  14. self.window!.backgroundColor = UIColor(red: 9/255, green: 4/255, blue: 68/255, alpha: 1)
  15. self.window!.makeKeyAndVisible()
  16.  
  17. // rootViewController from StoryBoard
  18. let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
  19. let navigationController = mainStoryboard.instantiateViewController(withIdentifier: "navigationController")
  20. self.window!.rootViewController = navigationController
  21.  
  22. // logo mask
  23. navigationController.view.layer.mask = CALayer()
  24. navigationController.view.layer.mask!.contents = UIImage(named: "logo.png")!.cgImage
  25. navigationController.view.layer.mask!.bounds = CGRect(x: 0, y: 0, width: 60, height: 60)
  26. navigationController.view.layer.mask!.anchorPoint = CGPoint(x: 0.5, y: 0.5)
  27. navigationController.view.layer.mask!.position = CGPoint(x: navigationController.view.frame.width / 2, y: navigationController.view.frame.height / 2)
  28.  
  29. // logo mask background view
  30. let maskBgView = UIView(frame: navigationController.view.frame)
  31. maskBgView.backgroundColor = UIColor.white
  32. navigationController.view.addSubview(maskBgView)
  33. navigationController.view.bringSubview(toFront: maskBgView)
  34.  
  35. // logo mask animation
  36. let transformAnimation = CAKeyframeAnimation(keyPath: "bounds")
  37. transformAnimation.delegate = self as? CAAnimationDelegate
  38. transformAnimation.duration = 1
  39. transformAnimation.beginTime = CACurrentMediaTime() + 1 //add delay of 1 second
  40. let initalBounds = NSValue(cgRect: (navigationController.view.layer.mask!.bounds))
  41. let secondBounds = NSValue(cgRect: CGRect(x: 0, y: 0, width: 50, height: 50))
  42. let finalBounds = NSValue(cgRect: CGRect(x: 0, y: 0, width: 2000, height: 2000))
  43. transformAnimation.values = [initalBounds, secondBounds, finalBounds]
  44. transformAnimation.keyTimes = [0, 0.5, 1]
  45. transformAnimation.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut), CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)]
  46. transformAnimation.isRemovedOnCompletion = false
  47. transformAnimation.fillMode = kCAFillModeForwards
  48. navigationController.view.layer.mask!.add(transformAnimation, forKey: "maskAnimation")
  49.  
  50. // logo mask background view animation
  51. UIView.animate(withDuration: 0.1,
  52. delay: 1.35,
  53. options: UIViewAnimationOptions.curveEaseIn,
  54. animations: {
  55. maskBgView.alpha = 0.0
  56. },
  57. completion: { finished in
  58. maskBgView.removeFromSuperview()
  59. })
  60.  
  61. // root view animation
  62. UIView.animate(withDuration: 0.25,
  63. delay: 1.3,
  64. options: UIViewAnimationOptions(),
  65. animations: {
  66. self.window!.rootViewController!.view.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
  67. },
  68. completion: { finished in
  69. UIView.animate(withDuration: 0.3,
  70. delay: 0.0,
  71. options: UIViewAnimationOptions(),
  72. animations: {
  73. self.window!.rootViewController!.view.transform = CGAffineTransform.identity
  74. },
  75. completion: nil
  76. )
  77.  
  78. do {
  79. self.audioPlayer = try AVAudioPlayer(contentsOf: URL.init(fileURLWithPath: Bundle.main.path(forResource: "startup", ofType: "wav")!))
  80. self.audioPlayer.prepareToPlay()
  81. }
  82. catch {
  83. print(error)
  84. }
  85. })
  86.  
  87. return true
  88.  
  89. }
  90.  
  91.  
  92.  
  93. func applicationWillResignActive(_ application: UIApplication) {
  94. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  95. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  96. }
  97.  
  98. func applicationDidEnterBackground(_ application: UIApplication) {
  99. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  100. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  101. }
  102.  
  103. func applicationWillEnterForeground(_ application: UIApplication) {
  104. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
  105. }
  106.  
  107. func applicationDidBecomeActive(_ application: UIApplication) {
  108. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  109. }
  110.  
  111. func applicationWillTerminate(_ application: UIApplication) {
  112. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  113. }
  114.  
  115.  
  116. }
  117.  
  118. var audioPlayer = AVAudioPlayer()
  119.  
  120. func playSound(file:String, ext:String) -> Void {
  121. do {
  122. let url = URL.init(fileURLWithPath: Bundle.main.path(forResource: file, ofType: ext)!)
  123. audioPlayer = try AVAudioPlayer(contentsOf: url)
  124. audioPlayer.prepareToPlay()
  125. audioPlayer.play()
  126. } catch let error {
  127. NSLog(error.localizedDescription)
  128. }
  129. }
  130.  
  131. playSound(file: "startup", ext: "wav")
Add Comment
Please, Sign In to add comment