Created
July 11, 2017 03:04
-
-
Save staycreativedesign/9014acf9ea02966c6e4fde4f6504d6eb to your computer and use it in GitHub Desktop.
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
// | |
// CustomTableViewCell.swift | |
// PassingInfoToSegue | |
// | |
// Created by Gustavo Pares on 7/7/17. | |
// Copyright © 2017 Gustavo Pares. All rights reserved. | |
// | |
import UIKit | |
class CustomTableViewCell : UITableViewCell { | |
var isAnimated = false | |
} |
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 pointsTable: UITableView! | |
@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) | |
print(" content size \(pointsTable.contentSize.height)") | |
print(" bound size \(pointsTable.bounds.size.height)") | |
} | |
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.alwaysBounceVertical = false | |
tableView.separatorStyle = .none | |
tableView.allowsSelection = false | |
tableView.bounces = true | |
print(" content size \(pointsTable.contentSize.height)") | |
print(" bound size \(tableView.bounds.size.height)") | |
print(" tableview content size \(tableView.contentSize.height)") | |
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) | |
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