讓其他按鍵都觸發 model 相對應的方法
This commit is contained in:
@@ -27,6 +27,9 @@
|
|||||||
<state key="normal" title=".">
|
<state key="normal" title=".">
|
||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickDotButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="n4O-i6-tej"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="jgo-wI-dJm">
|
<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"/>
|
<rect key="frame" x="192" y="557" width="80" height="80"/>
|
||||||
@@ -35,6 +38,9 @@
|
|||||||
<state key="normal" title="=">
|
<state key="normal" title="=">
|
||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickEquationButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Wlj-nE-CFP"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iKJ-gm-pgJ">
|
<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"/>
|
<rect key="frame" x="16" y="557" width="80" height="80"/>
|
||||||
@@ -153,6 +159,9 @@
|
|||||||
<state key="normal" title="AC">
|
<state key="normal" title="AC">
|
||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickAllClearButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Ovk-lI-xeN"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="I4O-WX-Rsc">
|
<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"/>
|
<rect key="frame" x="104" y="205" width="168" height="80"/>
|
||||||
@@ -161,36 +170,54 @@
|
|||||||
<state key="normal" title="+/-">
|
<state key="normal" title="+/-">
|
||||||
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
<color key="titleColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||||
</state>
|
</state>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickInversionButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="qMX-2i-KY2"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Dlz-OI-x3i">
|
<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"/>
|
<rect key="frame" x="280" y="205" width="80" height="80"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="18"/>
|
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="18"/>
|
||||||
<state key="normal" title="%"/>
|
<state key="normal" title="%"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickPercentButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="sKA-Mn-mXq"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="icb-C3-YOh">
|
<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"/>
|
<rect key="frame" x="280" y="557" width="80" height="80"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
||||||
<state key="normal" title="+"/>
|
<state key="normal" title="+"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickPlusButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Jtc-RR-BM3"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JAI-XN-CDt">
|
<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"/>
|
<rect key="frame" x="280" y="469" width="80" height="80"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="42"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="42"/>
|
||||||
<state key="normal" title="-"/>
|
<state key="normal" title="-"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickMinusButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="F3p-G6-2vG"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cuz-9a-BkO">
|
<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"/>
|
<rect key="frame" x="280" y="381" width="80" height="80"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
||||||
<state key="normal" title="×"/>
|
<state key="normal" title="×"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickMultiplicationButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="QmT-uo-S8J"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RA4-Vt-6OG">
|
<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"/>
|
<rect key="frame" x="280" y="293" width="80" height="80"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
<fontDescription key="fontDescription" type="system" weight="light" pointSize="34"/>
|
||||||
<state key="normal" title="÷"/>
|
<state key="normal" title="÷"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="clickDivisionButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="JbS-w3-mTU"/>
|
||||||
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hLf-ut-UVB">
|
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hLf-ut-UVB">
|
||||||
<rect key="frame" x="0.0" y="0.0" width="375" height="204"/>
|
<rect key="frame" x="0.0" y="0.0" width="375" height="204"/>
|
||||||
|
|||||||
@@ -12,4 +12,40 @@ class Calculator {
|
|||||||
func clickNumber(_ number: Int) {
|
func clickNumber(_ number: Int) {
|
||||||
print(number)
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,42 @@ class ViewController: UIViewController {
|
|||||||
calculator.clickNumber(number)
|
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() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
// Do any additional setup after loading the view.
|
// Do any additional setup after loading the view.
|
||||||
|
|||||||
Reference in New Issue
Block a user