Created
July 10, 2017 16:11
-
-
Save staycreativedesign/6e7d8a55cdfcba97f91db77534c60dc0 to your computer and use it in GitHub Desktop.
points.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PointsController.swift | |
// PassingInfoToSegue | |
// | |
// Created by Gustavo Pares on 7/5/17. | |
// Copyright © 2017 Gustavo Pares. All rights reserved. | |
// | |
import UIKit | |
class PointsController: UIViewController, UITableViewDataSource, UITableViewDelegate { | |
var finalPoints = [Card]() | |
var correctAnswers = 0 | |
let queue = OperationQueue() | |
var testCards = [Card]() | |
@IBOutlet weak var totalPoints: UILabel! | |
override open var shouldAutorotate: Bool { | |
return false | |
} | |
override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
return .portrait | |
} | |
override var prefersStatusBarHidden: Bool { | |
return true | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let infoLayer = self.view.layer | |
infoLayer.cornerRadius = 20.0 | |
infoLayer.borderWidth = 10.0 | |
infoLayer.borderColor = UIColor.white.cgColor | |
infoLayer.backgroundColor = UIColor(red:0.22, green:0.04, blue:0.27, alpha:1.0).cgColor | |
queue.maxConcurrentOperationCount = 1 | |
totalPoints.text = String(correctAnswers) | |
totalPoints.font = UIFont(name: "DKFrozenMemory-Regular", size: 32) | |
} | |
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return(finalPoints.count) | |
} | |
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let card = finalPoints[indexPath.row] | |
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell | |
tableView.separatorStyle = .none | |
tableView.allowsSelection = false | |
tableView.bounces = true | |
tableView.backgroundColor = UIColor(red:0.22, green:0.04, blue:0.27, alpha:1.0) | |
cell.backgroundColor = UIColor(red:0.22, green:0.04, blue:0.27, alpha:1.0) | |
cell.textLabel?.textColor = card.color | |
cell.textLabel?.textAlignment = .center | |
cell.textLabel?.font = UIFont(name: "Helvetica", size: 28) | |
cell.textLabel?.text = card.name | |
cell.isHidden = true | |
// if number of cells is greater than view table height still continue to show cells (automatic scroll) | |
let numberOfRows = tableView.numberOfRows(inSection: 0) | |
let indexPath = IndexPath(row: numberOfRows-1 , section: 0) | |
tableView.scrollToRow(at: indexPath, at: UITableViewScrollPosition.middle, animated: true) | |
if(cell.isAnimated) { | |
cell.isHidden = false | |
print("im animated") | |
} else { | |
cell.isAnimated = true | |
print("im not animated") | |
queue.addOperation { | |
print("hey \(indexPath.row) \(Date())") | |
usleep(500000) | |
DispatchQueue.main.async { | |
UIView.animate(withDuration: 1.0, animations: { | |
print("\(card) inside animate") | |
if card.outcome == .right { | |
self.correctAnswers += 1 | |
self.totalPoints.text = String(self.correctAnswers) | |
print("added point") | |
} | |
}) | |
cell.isHidden = false | |
} | |
} | |
} | |
return(cell) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment