Cov txheej txheem:
- Kauj Ruam 1: Tsim Txoj Haujlwm
- Kauj ruam 2: Storyboard Layout
- Kauj Ruam 3: Tsim Zaj Dab Neeg thiab Kev Zoo Nkauj
- Kauj Ruam 4: Sib Txuas thiab Sib Koom Ua Ke
- Kauj Ruam 5: Tsim Kev Hloov
- Kauj Ruam 6: Tus Naj Npawb Ua Haujlwm
- Kauj Ruam 7: Kev Ua Haujlwm Cov Khawm
- Kauj Ruam 8: Lwm Yam Ua Ntej Ua Ntej
- Kauj ruam 9: Tag Nrho Cov Cai
Video: Yuav Ua Li Cas Lub Xeem Hauv Xcode Siv Swift: 9 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:30
Hauv qhov kev qhia nrawm no, kuv yuav qhia koj yuav tsim lub tshuab xam zauv yooj yim siv Swift hauv Xcode li cas. Cov app no tau tsim los saib yuav luag zoo ib yam rau thawj lub tshuab xam zauv app rau iOS. Koj tuaj yeem ua raws cov lus qhia ib qib zuj zus thiab tsim lub tshuab xam zauv nrog kuv, lossis koj tuaj yeem yooj yim mus rau cov kauj ruam kawg thiab luam thiab muab cov cai tso rau hauv koj tus saib xyuas. Txawm li cas los xij, yog tias koj ua qhov no, nco ntsoov txuas tag nrho koj cov ntsiab lus ntawm zaj dab neeg nrog koj tus saib xyuas.
Kauj Ruam 1: Tsim Txoj Haujlwm
Thawj kauj ruam hauv kev ua peb lub laij lej yog los tsim qhov haujlwm hauv Xcode. Koj tuaj yeem ua qhov no los ntawm txhaj "Tsim qhov tshiab Xcode project" thiab npe nws txhua yam koj xav tau. Kuv lub npe hu ua "Calculator." Cov kauj ruam tom ntej yog xaiv "Daim Ntawv Thov Ib Leeg" rau hom app. Khaws tag nrho lwm cov ntaub ntawv raws li tus nqi pib.
Kauj ruam 2: Storyboard Layout
Kauj Ruam 2 ntawm kev tsim peb lub laij lej xav kom koj tsim tus qauv yooj yim hauv zaj dab neeg. Ua ntej koj pib qhov no, Kuv pom zoo hloov koj lub cuab yeej simulation mus rau iPhone 7 Plus. Pib los ntawm rub lub pob rau ntawm zaj dab neeg thiab hloov nws qhov ntev mus rau 89 x 89. Hloov nws cov xim keeb kwm yav dhau rau mercury ntawm tus cwj pwm tshuaj xyuas thiab nws cov xim xim rau tungsten. Tom ntej no, kho qhov font mus rau Helvetica Light 30. Txuas mus ntxiv thiab muab tshuaj txhuam khawm kom txog thaum koj muaj tag nrho ntawm 20. Kho qhov teeb tsa ntawm cov nyees khawm no kom koj muaj tsib kab thiab plaub kab.
Kauj Ruam 3: Tsim Zaj Dab Neeg thiab Kev Zoo Nkauj
Rho tawm khawm thib ob ntawm kab hauv qab thiab nthuav thawj lub pob kom hla qhov chaw no. Hloov qhov chaw tso tus nqi ntawm lub pob no rau xoom. Txuas ntxiv hloov tus lej tus lej thiab cov cim ntawm txhua lub pob kom txog thaum nws zoo ib yam hauv daim duab uas tau hais los saum no. Ntawm tus kws tshuaj xyuas tus cwj pwm, xim tsaus nti yog nyiaj, xim txiv kab ntxwv yog tangerine, thiab xim xim tau hloov mus rau daus ntawm cov txiv kab ntxwv. Tom ntej no, nyem rau ntawm tus saib saib thiab hloov nws cov xim keeb kwm yav dhau rau dub. Ntxiv daim ntawv lo rau saum cov nyees khawm thiab kho nws qhov loj me txawm li cas los koj xav xis nyob. Teem cov ntawv mus rau sab xis thiab hloov daim ntawv lo rau font Helvetica lub teeb 70. Yog tias koj xav tau, koj tuaj yeem ntxiv cov kev txwv rau txhua yam hauv kev txhawm rau ua kom lub app zoo ib yam rau txhua lub cuab yeej.
Kauj Ruam 4: Sib Txuas thiab Sib Koom Ua Ke
Qhib tus kws tshuaj xyuas tus cwj pwm thiab hloov daim ntawv rau txhua tus lej tus lej. Cov ntawv yuav tsum yog 1 ntau tshaj qhov muaj nuj nqis tiag. Piv txwv li, #0 khawm yuav tsum muaj tus lej cim npe ntawm 1, khawm #1 yuav tsum muaj tus lej cim ntawm 2, khawm #2 yuav tsum muaj tus lej cim npe ntawm 3, thiab ntxiv rau. Tom ntej no, nyem tswj, nyem rau ntawm #0 khawm, thiab rub nws mus rau qhov saib xyuas. Ib qho popup yuav tsum tshwm ntawm qhov screen. Hloov qhov kev txuas mus rau 'kev nqis tes ua,' hom rau 'UIButton,' qhov xwm txheej mus rau 'Touch Up Inside,' cov lus sib cav rau 'Sender,' thiab nws lub npe rau 'lej.' Koj tuaj yeem hloov lub npe mus rau txhua yam uas koj xav tau tab sis qhov ntawd txhais tau tias koj yuav tau hloov lub npe dua thaum hu ua haujlwm tom qab ntawm qhov haujlwm. Tom ntej no, tswj hwm, nyem, thiab luag txhua tus lej khawm mus rau qhov haujlwm uas peb nyuam qhuav tsim. Tam sim no, tswj, nyem, thiab rub daim ntawv lo rau hauv qhov haujlwm, tab sis TSIS YOG rau hauv txoj haujlwm. Qhov no txhais tau tias koj tsuas yog nqa daim ntawv lo rau hauv txoj haujlwm raws li qhov sib txawv sib txawv. Nco ntsoov, yog tias koj ib txwm tsis meej pem txog cov cai, Kuv tau tso tag nrho kuv cov cai rau koj siv rau theem kawg ntawm Cov Lus Qhia no.
Kauj Ruam 5: Tsim Kev Hloov
Txhawm rau ua kom peb cov lej lej ua haujlwm, peb yuav tsum txuas lawv tus nqi rau daim ntawv lo hauv peb 'cov lej' ua haujlwm. Koj tuaj yeem ua qhov no los ntawm kev xub tsim qhov sib txawv 'numberOnScreen' thiab ua nws hom ob npaug thiab sib npaug rau 0: var numberOnScreen: Ob npaug = 0; Thiab tsis txhob hnov qab, yog tias cov cai ntawm no tsis meej me ntsis, Kuv tau tso koj tag nrho cov cai ntawm cov kauj ruam kawg rau koj siv rau qhov koj nyiam. Tom ntej no, tsim kom muaj lwm qhov sib txawv 'performingMath' ntawm hom bool thiab ua rau nws cuav: var performingMath = cuav; Tsis tas li, tsim lwm qhov sib txawv hu ua 'previousNumber' ntawm hom ob thiab teeb nws sib npaug rau 0: var yav dhau losNumber: Ob npaug = 0; Qhov sib txawv kawg uas koj yuav tsum tsim yog 'kev ua haujlwm' sib txawv. Teem nws sib npaug rau 0: var ua haujlwm = 0;
Kauj Ruam 6: Tus Naj Npawb Ua Haujlwm
Tom qab koj tau tsim cov kev hloov pauv uas tsim nyog, koj tuaj yeem npaj mus theej thiab muab cov lej no tso rau hauv koj li 'lej' ua haujlwm:
yog tias ua tauMath == muaj tseeb {
label.text = Txoj hlua (sender.tag-1)
numberOnScreen = Ob npaug (ntawv lo lus!)!
performingMath = tsis tseeb
}
lwm tus {
label.text = ntawv.text! + Txoj hlua (sender.tag-1)
numberOnScreen = Ob npaug (ntawv lo lus!)!
}
Qhov tseem ceeb, tsab cai no qhia qee tus lej ntawm daim ntawv lo thaum lub khawm tsim nyog raug nias. Txawm li cas los xij, peb tseem yuav tsum muaj peev xwm siv tag nrho lwm cov nyees khawm thiab ua lub laij lej ua haujlwm. Peb yuav ua qhov no hauv ob peb kauj ruam tom ntej.
Kauj Ruam 7: Kev Ua Haujlwm Cov Khawm
Qhib tus kws tshuaj xyuas tus cwj pwm thiab hloov daim ntawv rau txhua qhov khawm sib txawv. Lub pob kom meej yuav tsum muaj tag ntawm 11, khawm faib yuav tsum muaj tag ntawm 12, khawm sib npaug yuav tsum muaj tag ntawm 13, khawm rho tawm yuav tsum muaj tag ntawm 14, khawm ntxiv yuav tsum muaj tag ntawm 15, thiab khawm sib npaug yuav tsum muaj tag lossis 16. Tom ntej no, nias tswj, nyem rau ntawm lub pob kom meej, thiab rub nws mus rau tus saib xyuas. Ib qho popup yuav tsum tshwm ntawm qhov screen. Hloov qhov kev txuas mus rau 'kev nqis tes ua,' hom rau 'UIButton,' qhov xwm txheej mus rau 'Touch Up Inside,' cov lus sib cav rau 'Sender,' thiab nws lub npe rau 'nyees khawm.' Koj tuaj yeem hloov lub npe mus rau txhua yam uas koj xav tau tab sis qhov ntawd txhais tau tias koj yuav tau hloov lub npe dua thaum hu ua haujlwm tom qab ntawm qhov haujlwm. Tom ntej no, tswj hwm, nyem, thiab rub txhua pob sib txawv rau hauv qhov haujlwm uas peb nyuam qhuav tsim.
Kauj Ruam 8: Lwm Yam Ua Ntej Ua Ntej
Tom qab koj tau txuas tag nrho cov cim npe sib txawv khawm rau lawv txoj haujlwm tsim nyog, koj tuaj yeem pib ntxig cov cai rau hauv 'khawm' ua haujlwm:
yav dhau losNumber = Ob npaug (ntawv lo lus!)!
yog sender.tag == 12 {// Faib
label.text = "/";
}
yog sender.tag == 13 {// Multiply
label.text = "x";
}
yog tias sender.tag == 14 {// Rho tawm
label.text = "-";
}
yog sender.tag == 15 {// Ntxiv
label.text = "+";
}
ua haujlwm = sender.tag
performingMath = muaj tseeb;
}
lwm yog sender.tag == 16 {
yog ua haujlwm == 12 {// Faib
label.text = Txoj hlua (yav dhau losNumber / numberOnScreen)
}
lwm tus yog tias ua haujlwm == 13 {// Multiply
label.text = Txoj hlua (yav dhau losNumber * numberOnScreen)
}
lwm yog ua haujlwm == 14 {// Rho tawm
label.text = Txoj hlua (yav dhau losNumber - numberOnScreen)
}
lwm yog kev ua haujlwm == 15 {// Ntxiv
label.text = Txoj hlua (yav dhau losNumber + numberOnScreen)
}
}
lwm yog sender.tag == 11 {
ntawv.text = ""
yav dhau losNumber = 0;
numberOnScreen = 0;
kev ua haujlwm = 0;
}
Qhov tseem ceeb, daim ntawv no qhia txog ib qho ntawm lwm cov nyees khawm thaum nws raug nias thiab ua tiav los laij cov lus teb kawg thiab nthuav tawm nws ntawm daim ntawv lo.
Kauj ruam 9: Tag Nrho Cov Cai
Yog tias koj tsis xav mus dhau thiab tsim lub tshuab xam zauv ib kauj ruam nrog kuv, tom qab ntawd koj tuaj yeem yooj yim ntxiv cov ntsiab lus rau hauv koj zaj dab neeg thiab luam thiab muab cov lej tag nrho tso rau hauv koj tus saib xyuas. Nov yog cov cai:
ntshuam UIKit
chav ViewController: UIViewController {
var numberOnScreen: Ob npaug = 0;
var yav dhau losNumber: Ob npaug = 0;
var performingMath = cuav;
var ua = 0;
@IBAction func tooj (_ tus xa: UIButton) {
yog tias ua tauMath == muaj tseeb {
label.text = Txoj hlua (sender.tag-1)
numberOnScreen = Ob npaug (ntawv lo lus!)!
performingMath = tsis tseeb
}
lwm tus {
label.text = ntawv.text! + Txoj hlua (sender.tag-1)
numberOnScreen = Ob npaug (ntawv lo lus!)!
}
}
@IBOutlet tsis muaj zog var daim ntawv lo: UILabel!
@IBAction func nyees khawm (_ tus xa: UIButton) {
yog label.text! = "" && sender.tag! = 11 && sender.tag! = 16 {
yav dhau losNumber = Ob npaug (ntawv lo lus!)!
yog sender.tag == 12 {// Faib
label.text = "/";
}
yog sender.tag == 13 {// Multiply
label.text = "x";
}
yog tias sender.tag == 14 {// Rho tawm
label.text = "-";
}
yog sender.tag == 15 {// Ntxiv
label.text = "+";
}
ua haujlwm = sender.tag
performingMath = muaj tseeb;
}
lwm yog sender.tag == 16 {
yog ua haujlwm == 12 {// Faib
label.text = Txoj hlua (yav dhau losNumber / numberOnScreen)
}
lwm tus yog tias ua haujlwm == 13 {// Multiply
label.text = Txoj hlua (yav dhau losNumber * numberOnScreen)
}
lwm yog ua haujlwm == 14 {// Rho tawm
label.text = Txoj hlua (yav dhau losNumber - numberOnScreen)
}
lwm yog kev ua haujlwm == 15 {// Ntxiv
label.text = Txoj hlua (yav dhau losNumber + numberOnScreen)
}
}
lwm yog sender.tag == 11 {
ntawv.text = ""
yav dhau losNumber = 0;
numberOnScreen = 0;
kev ua haujlwm = 0;
}
}
override func viewDidLoad () {
super.viewDidLoad ()
// Ua ib qho kev teeb tsa ntxiv tom qab thauj khoom pom, feem ntau los ntawm tus nib.
}
override func didReceiveMemoryWarning () {
super.didReceiveMemoryWarning ()
// Muab pov tseg ntawm cov peev txheej uas tuaj yeem rov tsim dua.
}
}
Pom zoo:
Yuav Ua Li Cas Tsis Siv Lub Qhov Rooj Tsis Tshua, Lub Cev Kub Lub Cev, GY-906, 433MHz Siv Arduino: 3 Kauj Ruam
Yuav Ua Li Cas Tsis Siv Lub Qhov Rooj Tsis Tuaj, Lub Cev Kub Lub Cev, GY-906, 433MHz Siv Arduino: Hnub no peb yuav ua lub qhov rooj tsis kov, nws yuav ntsuas koj lub cev kub. Hauv qhov xwm txheej tam sim no, Nws yog ib qho tseem ceeb heev uas yuav tsum paub yog tias ib tus neeg lub cev kub ntau dua li ib txwm, thaum ib tus neeg raug ncaws tawm
Yuav Ua Li Cas Tic Tac Toe Game Siv Swift Nrog Xcode: 5 Kauj Ruam
Yuav Ua Li Cas Tic Tac Toe Game Siv Swift Nrog Xcode: Hauv qhov kev qhia Swift no kuv yuav qhia koj yuav tsim Tic Tac Toe App li cas. Cov app no yooj yim heev thiab yog txoj haujlwm zoo rau txhua tus pib. Kuv yuav tawg qhov kev qhia ua peb theem: 1. Tsim cov khoom 2. Txuas cov khoom rau hauv txoj cai 3. Cov c
Yuav Ua Li Cas Thiaj Li Laus Kev Xeem Kev Xeem Siv MATLAB: 6 Kauj Ruam
Yuav Ua Li Cas Txheeb Tus Neeg Laus Hnov Lus Siv MATLAB: DISCLAIMER: Peb qhov kev xeem tsis yog kuaj mob thiab yuav tsum tsis txhob siv li ntawd. Txhawm rau ntsuas qhov hnov lus zoo, thov mus ntsib kws kho mob.Kev siv cov ntaub ntawv uas peb twb muaj lawm, peb pab pawg tau kuaj qhov hnov lus. Peb qhov kev xeem yog rau cov neeg laus thiab cov hluas siv nkaus xwb
Yuav Ua Li Cas Siv Tinkercad los Xeem & Siv Koj Cov Khoos Phis Tawj: 5 Kauj Ruam (nrog Duab)
Yuav Ua Li Cas Siv Tinkercad los Xeem & Siv Koj Cov Khoos Phis Tawj: Kev sim Circuit yog txheej txheem uas lub khoos phis tawj siv lub computer sim ua tus cwj pwm ntawm kev siv hluav taws xob lossis kab ke. Kev tsim qauv tshiab tuaj yeem sim, ntsuas thiab ntsuas yam tsis tau tsim lub hauv paus lossis kab ke. Simulation Circuit tej zaum yuav yog
Yuav Ua Li Cas Tau Txais Cov Nkauj Los Ntawm Txhua Qhov (Haha) Lub Vev Xaib (Ntev Li Koj Tau hnov Nws Koj Yuav Tau Txais Nws Ok Zoo Yog Nws Tau Ntxig Hauv Flash Koj Yuav Tsis Muaj Peev Xwm) EDITED !!!!! Ntxiv Info: 4 Cov Kauj Ruam
Yuav Ua Li Cas Tau Txais Cov Nkauj Los Ntawm Txhua Qhov (Haha) Lub Vev Xaib (Ntev Li Koj Tau hnov Nws Koj Yuav Tau Txais Nws … Ok Zoo Yog Nws Tau Ntxig Hauv Flash Koj Yuav Tsis Muaj Peev Xwm) EDITED !!!!! Ntxiv Cov Lus Qhia: yog tias koj tau mus rau lub vev xaib thiab nws ua nkauj nkauj uas koj nyiam thiab xav tau nws ntawm no yog cov lus qhia rau koj tsis yog kuv qhov txhaum yog tias koj cuam tshuam qee yam (tsuas yog txoj hauv kev nws yuav tshwm sim yog tias koj pib tshem cov khoom yam tsis muaj laj thawj. ) Kuv tuaj yeem tau txais cov nkauj rau