Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
066dc2b386 | ||
|
|
6aff162426 | ||
|
|
0640f65746 | ||
|
|
34741d614e | ||
|
|
97fc9d92c3 | ||
|
|
34ba756807 | ||
|
|
990ab4d897 | ||
|
|
3387d557c5 | ||
|
|
3187886ab1 | ||
|
|
13128d5152 | ||
|
|
2e74e12cb0 | ||
|
|
0312806ea9 | ||
|
|
7928e2d70d | ||
|
|
b566021273 |
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
# Xcode
|
||||||
|
#
|
||||||
|
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||||
|
|
||||||
|
## User settings
|
||||||
|
xcuserdata/
|
||||||
|
|
||||||
|
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
|
||||||
|
*.xcscmblueprint
|
||||||
|
*.xccheckout
|
||||||
|
|
||||||
|
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
|
||||||
|
build/
|
||||||
|
DerivedData/
|
||||||
|
*.moved-aside
|
||||||
|
*.pbxuser
|
||||||
|
!default.pbxuser
|
||||||
|
*.mode1v3
|
||||||
|
!default.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
!default.mode2v3
|
||||||
|
*.perspectivev3
|
||||||
|
!default.perspectivev3
|
||||||
@@ -25,11 +25,40 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
</label>
|
</label>
|
||||||
|
<pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="l0r-dF-pdB">
|
||||||
|
<rect key="frame" x="0.0" y="141" width="375" height="162"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="dataSource" destination="Qye-JV-Pqh" id="02w-lm-Z9W"/>
|
||||||
|
<outlet property="delegate" destination="Qye-JV-Pqh" id="m1q-dS-MSb"/>
|
||||||
|
</connections>
|
||||||
|
</pickerView>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fgz-0X-Yzp">
|
||||||
|
<rect key="frame" x="169" y="585" width="36" height="30"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
|
<state key="normal" title="Clear"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="clearPressed:" destination="Qye-JV-Pqh" eventType="touchUpInside" id="k3c-P9-NUQ"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="k0f-EI-Kte">
|
||||||
|
<rect key="frame" x="170" y="491" width="34" height="30"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
|
<state key="normal" title="Start"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="startStopPressed:" destination="Qye-JV-Pqh" eventType="touchUpInside" id="0V3-fL-bco"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||||
<viewLayoutGuide key="safeArea" id="cf5-pJ-AmR"/>
|
<viewLayoutGuide key="safeArea" id="cf5-pJ-AmR"/>
|
||||||
</view>
|
</view>
|
||||||
<tabBarItem key="tabBarItem" title="Timer" id="btY-Uw-RMI"/>
|
<tabBarItem key="tabBarItem" title="Timer" id="btY-Uw-RMI"/>
|
||||||
|
<connections>
|
||||||
|
<outlet property="startStopButton" destination="k0f-EI-Kte" id="OT6-bi-f84"/>
|
||||||
|
<outlet property="timeLabel" destination="SOV-8m-KXd" id="hM0-Ka-UhC"/>
|
||||||
|
<outlet property="timePicker" destination="l0r-dF-pdB" id="VFa-sJ-uik"/>
|
||||||
|
</connections>
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="Mav-Yg-pGe" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="Mav-Yg-pGe" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
|||||||
@@ -8,7 +8,132 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class TimerViewController: UIViewController {
|
class TimerViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
|
||||||
|
var hour = 0.0
|
||||||
|
var minute = 0.0
|
||||||
|
var second = 0.0
|
||||||
|
var time = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
@IBAction func clearPressed(_ sender: UIButton) {
|
||||||
|
hour = 0.0
|
||||||
|
minute = 0.0
|
||||||
|
second = 0.0
|
||||||
|
time = 0.0
|
||||||
|
elapsedTime = 0.0
|
||||||
|
timeLabel.text = "00:00:00"
|
||||||
|
timePicker.isHidden = false
|
||||||
|
timePicker.reloadAllComponents()
|
||||||
|
isRunning = false
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBAction func startStopPressed(_ sender: UIButton) {
|
||||||
|
if isRunning == false {
|
||||||
|
isRunning = true
|
||||||
|
timePicker.isHidden = true
|
||||||
|
startStopButton.setTitle("Stop", for: UIControl.State.normal)
|
||||||
|
timeLoop()
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
isRunning = false
|
||||||
|
timePicker.isHidden = false
|
||||||
|
timePicker.reloadAllComponents()
|
||||||
|
startStopButton.setTitle("Start", for: UIControl.State.normal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBOutlet weak var startStopButton: UIButton!
|
||||||
|
|
||||||
|
@IBOutlet weak var timeLabel: UILabel!
|
||||||
|
|
||||||
|
@IBOutlet weak var timePicker: UIPickerView!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func numberOfComponents(in pickerView: UIPickerView) -> Int {
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
|
||||||
|
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
|
||||||
|
if component == 0{
|
||||||
|
return 99
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 60
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
|
||||||
|
return "\(row)"
|
||||||
|
}
|
||||||
|
|
||||||
|
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
||||||
|
hour = Double(timePicker.selectedRow(inComponent: 0))
|
||||||
|
minute = Double(timePicker.selectedRow(inComponent: 1))
|
||||||
|
second = Double(timePicker.selectedRow(inComponent: 2))
|
||||||
|
time = hour*3600 + minute*60 + second
|
||||||
|
let timeString = "\(timePicker.selectedRow(inComponent: 0)):\(timePicker.selectedRow(inComponent: 1)):\(timePicker.selectedRow(inComponent: 2))"
|
||||||
|
timeLabel.text! = timeString
|
||||||
|
}
|
||||||
|
|
||||||
|
var isRunning = false
|
||||||
|
var elapsedTime = 0.0
|
||||||
|
|
||||||
|
func timeLoop() {
|
||||||
|
DispatchQueue.global(qos: .background).async {
|
||||||
|
var currentTime = Date()
|
||||||
|
var previousTime = currentTime
|
||||||
|
|
||||||
|
while(self.isRunning) {
|
||||||
|
currentTime = Date()
|
||||||
|
self.elapsedTime += currentTime.timeIntervalSince(previousTime)
|
||||||
|
previousTime = currentTime
|
||||||
|
|
||||||
|
let hours = Int((self.time-self.elapsedTime))/3600
|
||||||
|
let minutes = (Int((self.time-self.elapsedTime))%3600)/60
|
||||||
|
let seconds = (Int((self.time-self.elapsedTime))%3600)%60
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let hourStr = String.init(format: "%d", hours)
|
||||||
|
let minuteStr = String.init(format: "%02d", minutes)
|
||||||
|
let secondsStr = String.init(format: "%02d", seconds)
|
||||||
|
let timeString = "\(hourStr):\(minuteStr):\(secondsStr)"
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.timeLabel.text! = timeString
|
||||||
|
}
|
||||||
|
|
||||||
|
if hours == 0 && minutes == 0 && seconds == 0{
|
||||||
|
let alertController = UIAlertController(title: "TIME IS UP",
|
||||||
|
message: "YOUR TIMER IS OVER",
|
||||||
|
preferredStyle: UIAlertController.Style.alert)
|
||||||
|
|
||||||
|
let defaultAction = UIAlertAction(title: "STOP BEING LAZY",
|
||||||
|
style: UIAlertAction.Style.cancel,
|
||||||
|
handler: nil)
|
||||||
|
|
||||||
|
// add the buttons into the alert controller object
|
||||||
|
alertController.addAction(defaultAction)
|
||||||
|
|
||||||
|
// display
|
||||||
|
self.present(alertController, animated: true, completion: nil)
|
||||||
|
|
||||||
|
self.finish()
|
||||||
|
self.isRunning = false
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func finish(){
|
||||||
|
elapsedTime = 0
|
||||||
|
startStopButton.setTitle("Start", for: UIControl.State.normal)
|
||||||
|
timePicker.isHidden = false
|
||||||
|
timePicker.reloadAllComponents()
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@@ -17,6 +142,8 @@ class TimerViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// MARK: - Navigation
|
// MARK: - Navigation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user