Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // TransferWaitingController.swift
- // KoinBonds
- //
- // Created by helmi taufiq alhakim on 12/02/20.
- // Copyright © 2020 helmi taufiq alhakim. All rights reserved.
- //
- import UIKit
- class TransferWaitingController: UIViewController, TransferProtocol {
- @IBOutlet weak var timerLabel: UILabel!
- @IBOutlet weak var transferView: TransferView!
- @IBOutlet weak var containerScrollView: UIScrollView!
- var currentMinute = 59
- var currentSecond = 59
- var currentHour = 71
- private var timer = Timer()
- private var timerIsOn = false
- private var dateNow: Date!
- override func viewDidLoad() {
- super.viewDidLoad()
- timerLabel.isHidden = false
- configureSubView()
- initTimer()
- initTransfer()
- }
- func configureSubView(){
- containerScrollView.addSubView(transferView)
- }
- func onClickTransfer(index: CGFloat, isExpand: Bool) {
- let frame = containerScrollView.convert(transferView.contentView.frame, from: transferView)
- containerScrollView.setContentOffset(CGPoint(x: 0, y: (frame.maxY - containerScrollView.bounds.size.height)), animated: true)
- }
- private func initTimer() {
- dateNow = Date()
- if !timerIsOn {
- timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(onTick), userInfo: nil, repeats: true)
- timerIsOn = true
- }
- }
- @objc func onTick() {
- if ((currentHour > 0 || currentMinute > 0 || currentSecond > 0) && (currentMinute >= 0 || currentHour >= 0)) {
- if (currentSecond == 0) {
- if (currentMinute == 0) {
- currentMinute = 59
- currentHour -= 1
- } else{
- currentMinute -= 1
- currentSecond = 59
- }
- }
- else if (currentSecond > 0) {
- currentSecond -= 1
- }
- else if (currentSecond < 1) {
- timer.invalidate()
- }
- if (currentHour >= 0) {
- timerLabel.text = NSLocalizedString("", comment: "") + " \(timeString(hour: TimeInterval(currentHour), minute: TimeInterval(currentMinute), second: TimeInterval(currentSecond)))"
- }
- }
- else {
- currentHour = 71
- currentMinute = 59
- currentSecond = 59
- timer.invalidate()
- timerIsOn = false
- timerLabel.isHidden = true
- }
- }
- private func timeString(hour: TimeInterval,minute: TimeInterval, second: TimeInterval) -> String {
- let hour = Int(hour)
- let minute = Int(minute) % 60
- let seconds = Int(second) % 60
- return String(format: "%02i:%02i:%02i", hour, minute, seconds)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement