讓其他按鍵都觸發 model 相對應的方法

This commit is contained in:
2020-05-06 03:22:47 +08:00
parent 551a7c68fd
commit 59a4311883
3 changed files with 99 additions and 0 deletions

View File

@@ -27,6 +27,9 @@
<state key="normal" title=".">
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
</state>
<connections>
<action selector="clickDotButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="n4O-i6-tej"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jgo-wI-dJm">
<rect key="frame" x="192" y="557" width="80" height="80"/>
@@ -35,6 +38,9 @@
<state key="normal" title="=">
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
</state>
<connections>
<action selector="clickEquationButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Wlj-nE-CFP"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iKJ-gm-pgJ">
<rect key="frame" x="16" y="557" width="80" height="80"/>
@@ -153,6 +159,9 @@
<state key="normal" title="AC">
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
</state>
<connections>
<action selector="clickAllClearButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Ovk-lI-xeN"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="I4O-WX-Rsc">
<rect key="frame" x="104" y="205" width="168" height="80"/>
@@ -161,36 +170,54 @@
<state key="normal" title="+/-">
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
</state>
<connections>
<action selector="clickInversionButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="qMX-2i-KY2"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Dlz-OI-x3i">
<rect key="frame" x="280" y="205" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="18"/>
<state key="normal" title="%"/>
<connections>
<action selector="clickPercentButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="sKA-Mn-mXq"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="icb-C3-YOh">
<rect key="frame" x="280" y="557" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
<state key="normal" title="+"/>
<connections>
<action selector="clickPlusButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Jtc-RR-BM3"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JAI-XN-CDt">
<rect key="frame" x="280" y="469" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="42"/>
<state key="normal" title="-"/>
<connections>
<action selector="clickMinusButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="F3p-G6-2vG"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cuz-9a-BkO">
<rect key="frame" x="280" y="381" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
<state key="normal" title="×"/>
<connections>
<action selector="clickMultiplicationButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="QmT-uo-S8J"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RA4-Vt-6OG">
<rect key="frame" x="280" y="293" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
<state key="normal" title="÷"/>
<connections>
<action selector="clickDivisionButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="JbS-w3-mTU"/>
</connections>
</button>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hLf-ut-UVB">
<rect key="frame" x="0.0" y="0.0" width="375" height="204"/>

View File

@@ -12,4 +12,40 @@ class Calculator {
func clickNumber(_ number: Int) {
print(number)
}
func clickDot() {
print(".")
}
func clickEquation() {
print("=")
}
func clickPlus() {
print("+")
}
func clickMinus() {
print("-")
}
func clickMultiplication() {
print("*")
}
func clickDivision() {
print("/")
}
func clickPercent() {
print("%")
}
func clickInversion() {
print("+/-")
}
func clickAllClear() {
print("AC")
}
}

View File

@@ -22,6 +22,42 @@ class ViewController: UIViewController {
calculator.clickNumber(number)
}
@IBAction func clickDotButton(_ sender: UIButton) {
calculator.clickDot()
}
@IBAction func clickEquationButton(_ sender: UIButton) {
calculator.clickEquation()
}
@IBAction func clickPlusButton(_ sender: UIButton) {
calculator.clickPlus()
}
@IBAction func clickMinusButton(_ sender: UIButton) {
calculator.clickMinus()
}
@IBAction func clickMultiplicationButton(_ sender: UIButton) {
calculator.clickMultiplication()
}
@IBAction func clickDivisionButton(_ sender: UIButton) {
calculator.clickDivision()
}
@IBAction func clickPercentButton(_ sender: UIButton) {
calculator.clickPercent()
}
@IBAction func clickInversionButton(_ sender: UIButton) {
calculator.clickInversion()
}
@IBAction func clickAllClearButton(_ sender: UIButton) {
calculator.clickAllClear()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.