top of page

RollingCoders Rocks! with Sound


1.Move asset to folder 2. Build background, select image 3. darkBlueBG 4. Search for the button and put in the middle of app 5. Change property to select power button image 6. Let's create a top screen (uiView) - 2nd layer 7. Let's set the background image to blue 8. Command space, digital color meter 9. Let's add an image view 10. Change image to aspect fill & chane image to about 1/5 screen smaller 11. Add rocket image 12.Let's add the rocket and set behind the cloud 13. Add RollingCoders Mode Label, and change color to white and BOLD 14. Copy and paste Hustle Mode to create ROCKS! label 15. Let's connect the UI to code using the assisted editor (ASSISTED EDITOR) 16. Clean up code {remove did receive memory warning function} 17. Let's create the @IBOutlets and @IBAction 18. Hide CloudHolder, RollingLbl and OnLbl 19. Let's add audio (import AVFouncation) 20. Create a var player: AVAudioPlayer! and path 21. Create do; catch to see errors if any

22. Automate

//

// ViewController.swift

// Let'sFly

//

// Created by Hao Tran on 5/25/18.

// Copyright © 2018 RollingCoders. All rights reserved.

//

import UIKit

import AVFoundation

class ViewController: UIViewController {

@IBOutlet weak var darkBlueGB: UIImageView!

@IBOutlet weak var powerBtn: UIButton!

@IBOutlet weak var cloudHolder: UIView!

@IBOutlet weak var rocket: UIImageView!

@IBOutlet weak var rollingLbl: UILabel!

@IBOutlet weak var onLbl: UILabel!

var player: AVAudioPlayer!

override func viewDidLoad() {

super.viewDidLoad()

let path = Bundle.main.path(forResource: "hustle-on", ofType: "wav")!

let url = URL(fileURLWithPath: path)

do {

player = try AVAudioPlayer(contentsOf: url)

player.prepareToPlay()

}catch let error as NSError {

print(error.description)

}

}

@IBAction func powerBtnPressed(_ sender: Any) {

//show cloud and hide power button

cloudHolder.isHidden = false

darkBlueGB.isHidden = true

powerBtn.isHidden = true

player.play()

UIView.animate(withDuration: 2.3, animations: {

self.rocket.frame = CGRect(x: 0, y: 250, width: 375, height: 128)

}) {(finish) in

self.rollingLbl.isHidden = false

self.onLbl.isHidden = false

}

}

}


Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page