Skip to corpus content
HIMR Public Corpustimestamped source index

Recording

How to make a pause and resume button for NSTimer in xcode 7!

2015-11-03 · 15 min

internet_archive
Machine transcript · wording, timing and speaker attribution may be wrong

Wording, speaker labels, and timestamps can still be wrong. A transcript does not establish that statements in the recording are factual. Use the source links and surrounding context.

Read summary

Expand to load the summary.

Open summary page ↗
Source information & transcript revisions

Transcript revisions

  1. rev_9e1406cad3d18d694b99a85007f1cdbdMachine-generated and unreviewed; may be wrong; not a verified quotation.
    enraw_asractive242 segments

Transcript

en
  1. Hello and welcome to this video.

    Segment details0:01–0:03 · rev_9e1406cad3d18d694b99a85007f1cdbd_0
  2. And in this video, I'm going to attempt to

    Segment details0:04–0:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_1
  3. show you how to make a pause and resume

    Segment details0:07–0:08 · rev_9e1406cad3d18d694b99a85007f1cdbd_2
  4. button for a game. So let's start a

    Segment details0:08–0:12 · rev_9e1406cad3d18d694b99a85007f1cdbd_3
  5. new project in Xcode and choose a one-side

    Segment details0:12–0:15 · rev_9e1406cad3d18d694b99a85007f1cdbd_4
  6. view, one, one-screen view, can't

    Segment details0:15–0:18 · rev_9e1406cad3d18d694b99a85007f1cdbd_5
  7. remember. So anyway, just get your— what's

    Segment details0:18–0:21 · rev_9e1406cad3d18d694b99a85007f1cdbd_6
  8. it called— and then get a You

    Segment details0:22–0:27 · rev_9e1406cad3d18d694b99a85007f1cdbd_7
  9. need a ViewController, which is this

    Segment details0:27–0:28 · rev_9e1406cad3d18d694b99a85007f1cdbd_8
  10. thing. Should be here already. And then we

    Segment details0:28–0:31 · rev_9e1406cad3d18d694b99a85007f1cdbd_9
  11. need to do right-click on here and do New

    Segment details0:32–0:34 · rev_9e1406cad3d18d694b99a85007f1cdbd_10
  12. File and do this

    Segment details0:34–0:38 · rev_9e1406cad3d18d694b99a85007f1cdbd_11
  13. one, and then just name it like Game or

    Segment details0:38–0:42 · rev_9e1406cad3d18d694b99a85007f1cdbd_12
  14. something. Doesn't really matter. And I

    Segment details0:43–0:46 · rev_9e1406cad3d18d694b99a85007f1cdbd_13
  15. think we change this to UIViewController.

    Segment details0:46–0:48 · rev_9e1406cad3d18d694b99a85007f1cdbd_14
  16. Was it actually? I can't remember.

    Segment details0:51–0:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_15
  17. UIViewController. Yeah, I think that was

    Segment details0:59–1:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_16
  18. it. Game or

    Segment details1:01–1:05 · rev_9e1406cad3d18d694b99a85007f1cdbd_17
  19. something. Okay,

    Segment details1:05–1:08 · rev_9e1406cad3d18d694b99a85007f1cdbd_18
  20. and then just save it, and then What

    Segment details1:11–1:16 · rev_9e1406cad3d18d694b99a85007f1cdbd_19
  21. do we do now? Okay, so we have our files

    Segment details1:17–1:20 · rev_9e1406cad3d18d694b99a85007f1cdbd_20
  22. up here. Okay, so first go to Storyboard,

    Segment details1:21–1:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_21
  23. and what we want to do is create an image

    Segment details1:24–1:26 · rev_9e1406cad3d18d694b99a85007f1cdbd_22
  24. so it's like sliding across the screen,

    Segment details1:26–1:28 · rev_9e1406cad3d18d694b99a85007f1cdbd_23
  25. and that's the image we're going to pause.

    Segment details1:29–1:31 · rev_9e1406cad3d18d694b99a85007f1cdbd_24
  26. So type down the bottom ImageView and

    Segment details1:31–1:35 · rev_9e1406cad3d18d694b99a85007f1cdbd_25
  27. drag it on. Now we need an image, and we

    Segment details1:35–1:39 · rev_9e1406cad3d18d694b99a85007f1cdbd_26
  28. don't have anything in the supporting

    Segment details1:40–1:40 · rev_9e1406cad3d18d694b99a85007f1cdbd_27
  29. files.

    Segment details1:40–1:41 · rev_9e1406cad3d18d694b99a85007f1cdbd_28
  30. I guess we don't really need anything.

    Segment details1:46–1:47 · rev_9e1406cad3d18d694b99a85007f1cdbd_29
  31. Okay, it doesn't have to be an image. We

    Segment details1:49–1:50 · rev_9e1406cad3d18d694b99a85007f1cdbd_30
  32. can do a label or button. So let's do a

    Segment details1:51–1:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_31
  33. label instead. Yeah, my label.

    Segment details1:54–1:58 · rev_9e1406cad3d18d694b99a85007f1cdbd_32
  34. Okay, so we have a label and we're going

    Segment details2:00–2:02 · rev_9e1406cad3d18d694b99a85007f1cdbd_33
  35. to make it scroll across the screen. So

    Segment details2:02–2:05 · rev_9e1406cad3d18d694b99a85007f1cdbd_34
  36. what we want in here is Game.h.

    Segment details2:05–2:11 · rev_9e1406cad3d18d694b99a85007f1cdbd_35
  37. What do we need? We need curly brackets,

    Segment details2:11–2:14 · rev_9e1406cad3d18d694b99a85007f1cdbd_36
  38. right? And then we want

    Segment details2:14–2:19 · rev_9e1406cad3d18d694b99a85007f1cdbd_37
  39. IBOutlet and then UILabel, and then just

    Segment details2:19–2:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_38
  40. name your label something. And then we

    Segment details2:23–2:26 · rev_9e1406cad3d18d694b99a85007f1cdbd_39
  41. need a void— hold on, let me check my,

    Segment details2:26–2:29 · rev_9e1406cad3d18d694b99a85007f1cdbd_40
  42. my other game. Where is it?

    Segment details2:30–2:32 · rev_9e1406cad3d18d694b99a85007f1cdbd_41
  43. Game.h should be— so

    Segment details2:38–2:43 · rev_9e1406cad3d18d694b99a85007f1cdbd_42
  44. UIKit.

    Segment details2:43–2:45 · rev_9e1406cad3d18d694b99a85007f1cdbd_43
  45. Now for the IBOutlet, we need in below

    Segment details2:48–2:51 · rev_9e1406cad3d18d694b99a85007f1cdbd_44
  46. the UIViewController and then curly

    Segment details2:52–2:54 · rev_9e1406cad3d18d694b99a85007f1cdbd_45
  47. brackets and then Close

    Segment details2:54–2:59 · rev_9e1406cad3d18d694b99a85007f1cdbd_46
  48. curly brackets, and then we can do the

    Segment details2:59–3:00 · rev_9e1406cad3d18d694b99a85007f1cdbd_47
  49. voids at the end.

    Segment details3:00–3:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_48
  50. So it should go underneath

    Segment details3:05–3:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_49
  51. UIViewController. So let's

    Segment details3:07–3:11 · rev_9e1406cad3d18d694b99a85007f1cdbd_50
  52. go back. So we go underneath

    Segment details3:11–3:15 · rev_9e1406cad3d18d694b99a85007f1cdbd_51
  53. there. Yeah,

    Segment details3:15–3:16 · rev_9e1406cad3d18d694b99a85007f1cdbd_52
  54. and then we need an IBAction, so we can

    Segment details3:20–3:24 · rev_9e1406cad3d18d694b99a85007f1cdbd_53
  55. make a button. To— we need a button to

    Segment details3:25–3:27 · rev_9e1406cad3d18d694b99a85007f1cdbd_54
  56. pause and resume the game.

    Segment details3:28–3:28 · rev_9e1406cad3d18d694b99a85007f1cdbd_55
  57. So first of all, we can have pause.

    Segment details3:32–3:36 · rev_9e1406cad3d18d694b99a85007f1cdbd_56
  58. Oh, this is wrong. Hold on. We need

    Segment details3:36–3:40 · rev_9e1406cad3d18d694b99a85007f1cdbd_57
  59. selector and name selector pause,

    Segment details3:40–3:42 · rev_9e1406cad3d18d694b99a85007f1cdbd_58
  60. and then do it like this so you have ID

    Segment details3:44–3:46 · rev_9e1406cad3d18d694b99a85007f1cdbd_59
  61. sender. And we also need an IBAction for

    Segment details3:46–3:50 · rev_9e1406cad3d18d694b99a85007f1cdbd_60
  62. resume. So it should look like this.

    Segment details3:50–3:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_61
  63. And we also need IBOutlet for our

    Segment details3:56–4:00 · rev_9e1406cad3d18d694b99a85007f1cdbd_62
  64. button, and we'll call it pause,

    Segment details4:00–4:02 · rev_9e1406cad3d18d694b99a85007f1cdbd_63
  65. and another one for resume.

    Segment details4:04–4:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_64
  66. Let me turn my keyboard lights on because

    Segment details4:11–4:13 · rev_9e1406cad3d18d694b99a85007f1cdbd_65
  67. it's getting dark.

    Segment details4:13–4:14 · rev_9e1406cad3d18d694b99a85007f1cdbd_66
  68. Okay, let's see if we can get this to work

    Segment details4:18–4:19 · rev_9e1406cad3d18d694b99a85007f1cdbd_67
  69. properly. Go to your storyboard.

    Segment details4:20–4:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_68
  70. Here it is. Get rid of this bit.

    Segment details4:24–4:25 · rev_9e1406cad3d18d694b99a85007f1cdbd_69
  71. Okay, no, not this one. Where was the one

    Segment details4:27–4:30 · rev_9e1406cad3d18d694b99a85007f1cdbd_70
  72. we had last time? The main storyboard.

    Segment details4:31–4:33 · rev_9e1406cad3d18d694b99a85007f1cdbd_71
  73. Yeah, that's it. Okay, now we need 2

    Segment details4:33–4:35 · rev_9e1406cad3d18d694b99a85007f1cdbd_72
  74. buttons. Drag it on

    Segment details4:35–4:38 · rev_9e1406cad3d18d694b99a85007f1cdbd_73
  75. the screen and just call it pause, and

    Segment details4:38–4:41 · rev_9e1406cad3d18d694b99a85007f1cdbd_74
  76. then copy and paste Copy,

    Segment details4:41–4:46 · rev_9e1406cad3d18d694b99a85007f1cdbd_75
  77. paste, yeah. And we'll name it Resume.

    Segment details4:46–4:49 · rev_9e1406cad3d18d694b99a85007f1cdbd_76
  78. Okay, so what's next? That's a good

    Segment details4:52–4:55 · rev_9e1406cad3d18d694b99a85007f1cdbd_77
  79. question. Click on the top bit, on the top

    Segment details4:55–4:58 · rev_9e1406cad3d18d694b99a85007f1cdbd_78
  80. border, then click on this one, the 6th

    Segment details4:58–5:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_79
  81. tab along. 1, 2, 3, 4, 5, 6.

    Segment details5:01–5:03 · rev_9e1406cad3d18d694b99a85007f1cdbd_80
  82. And you'll find— okay, so that

    Segment details5:04–5:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_81
  83. didn't work.

    Segment details5:08–5:08 · rev_9e1406cad3d18d694b99a85007f1cdbd_82
  84. There's something I'm missing. Oh yeah,

    Segment details5:14–5:15 · rev_9e1406cad3d18d694b99a85007f1cdbd_83
  85. we have to do this. Change class to,

    Segment details5:15–5:18 · rev_9e1406cad3d18d694b99a85007f1cdbd_84
  86. to game or something. Yeah, that's it.

    Segment details5:20–5:22 · rev_9e1406cad3d18d694b99a85007f1cdbd_85
  87. Okay, it should work now. But then, yep,

    Segment details5:22–5:25 · rev_9e1406cad3d18d694b99a85007f1cdbd_86
  88. we have label, drag it to label, and

    Segment details5:25–5:28 · rev_9e1406cad3d18d694b99a85007f1cdbd_87
  89. pause, drag to pause. Resume can be

    Segment details5:29–5:32 · rev_9e1406cad3d18d694b99a85007f1cdbd_88
  90. dragged to resume. And we want our— where

    Segment details5:32–5:36 · rev_9e1406cad3d18d694b99a85007f1cdbd_89
  91. do I be? Actions. Oh, here. Received

    Segment details5:36–5:39 · rev_9e1406cad3d18d694b99a85007f1cdbd_90
  92. actions. Pause and do touch up inside.

    Segment details5:40–5:42 · rev_9e1406cad3d18d694b99a85007f1cdbd_91
  93. And resume, touch up inside.

    Segment details5:44–5:47 · rev_9e1406cad3d18d694b99a85007f1cdbd_92
  94. Okay, so we have our buttons and our

    Segment details5:47–5:49 · rev_9e1406cad3d18d694b99a85007f1cdbd_93
  95. labels declared. We need to write the code

    Segment details5:49–5:52 · rev_9e1406cad3d18d694b99a85007f1cdbd_94
  96. to make the— well, we need to get rid of

    Segment details5:53–5:55 · rev_9e1406cad3d18d694b99a85007f1cdbd_95
  97. this first. Implementation game or

    Segment details5:55–5:59 · rev_9e1406cad3d18d694b99a85007f1cdbd_96
  98. something. Okay, make some room.

    Segment details5:59–6:02 · rev_9e1406cad3d18d694b99a85007f1cdbd_97
  99. Okay, so we want the label to move across

    Segment details6:04–6:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_98
  100. the screen. Let's just move these down

    Segment details6:07–6:09 · rev_9e1406cad3d18d694b99a85007f1cdbd_99
  101. here.

    Segment details6:09–6:09 · rev_9e1406cad3d18d694b99a85007f1cdbd_100
  102. We want this to move across the screen,

    Segment details6:12–6:13 · rev_9e1406cad3d18d694b99a85007f1cdbd_101
  103. so how do we do that? That's a good

    Segment details6:14–6:17 · rev_9e1406cad3d18d694b99a85007f1cdbd_102
  104. question because I can't remember off the

    Segment details6:17–6:20 · rev_9e1406cad3d18d694b99a85007f1cdbd_103
  105. top of my head.

    Segment details6:20–6:20 · rev_9e1406cad3d18d694b99a85007f1cdbd_104
  106. Okay, where is— but we need a timer,

    Segment details6:28–6:31 · rev_9e1406cad3d18d694b99a85007f1cdbd_105
  107. so let's make a timer. This can go— goes

    Segment details6:32–6:36 · rev_9e1406cad3d18d694b99a85007f1cdbd_106
  108. here, I think. So NSTimer,

    Segment details6:36–6:37 · rev_9e1406cad3d18d694b99a85007f1cdbd_107
  109. and we will call it— what

    Segment details6:40–6:45 · rev_9e1406cad3d18d694b99a85007f1cdbd_108
  110. should we call it— labelTimer.

    Segment details6:46–6:48 · rev_9e1406cad3d18d694b99a85007f1cdbd_109
  111. Right, and then we go to M, and then we

    Segment details6:52–6:56 · rev_9e1406cad3d18d694b99a85007f1cdbd_110
  112. do— where's

    Segment details6:56–7:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_111
  113. viewDidLoad? So viewDidLoad is what

    Segment details7:01–7:04 · rev_9e1406cad3d18d694b99a85007f1cdbd_112
  114. happens when the game starts. We need

    Segment details7:04–7:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_113
  115. the code. Let me get it from my other game

    Segment details7:07–7:09 · rev_9e1406cad3d18d694b99a85007f1cdbd_114
  116. for the timer. It's quite long.

    Segment details7:10–7:11 · rev_9e1406cad3d18d694b99a85007f1cdbd_115
  117. Where is it? No, game.m.

    Segment details7:19–7:21 · rev_9e1406cad3d18d694b99a85007f1cdbd_116
  118. So copy this just like it,

    Segment details7:26–7:29 · rev_9e1406cad3d18d694b99a85007f1cdbd_117
  119. like it, like it says on my screen. Go

    Segment details7:29–7:32 · rev_9e1406cad3d18d694b99a85007f1cdbd_118
  120. back to your game. Now just paste it in

    Segment details7:32–7:35 · rev_9e1406cad3d18d694b99a85007f1cdbd_119
  121. there. Now movement

    Segment details7:35–7:39 · rev_9e1406cad3d18d694b99a85007f1cdbd_120
  122. timer should be changed to your timer

    Segment details7:39–7:41 · rev_9e1406cad3d18d694b99a85007f1cdbd_121
  123. name. Ours was labelTimer. And this bit

    Segment details7:41–7:44 · rev_9e1406cad3d18d694b99a85007f1cdbd_122
  124. will be in the void here. We need to make

    Segment details7:44–7:47 · rev_9e1406cad3d18d694b99a85007f1cdbd_123
  125. a void right down here, so put void,

    Segment details7:47–7:50 · rev_9e1406cad3d18d694b99a85007f1cdbd_124
  126. and then let's name it LabelMovement.

    Segment details7:51–7:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_125
  127. And then this should be changed to

    Segment details7:56–7:57 · rev_9e1406cad3d18d694b99a85007f1cdbd_126
  128. LabelMovement. And then we'll make a void

    Segment details7:57–8:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_127
  129. in here called LabelMovement, and this

    Segment details8:01–8:05 · rev_9e1406cad3d18d694b99a85007f1cdbd_128
  130. is where the code is going to go to make

    Segment details8:06–8:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_129
  131. our label move. So I

    Segment details8:07–8:11 · rev_9e1406cad3d18d694b99a85007f1cdbd_130
  132. think I'm doing this right.

    Segment details8:11–8:12 · rev_9e1406cad3d18d694b99a85007f1cdbd_131
  133. So the next thing we need to do is label,

    Segment details8:18–8:20 · rev_9e1406cad3d18d694b99a85007f1cdbd_132
  134. choose this one, .center equals

    Segment details8:22–8:25 · rev_9e1406cad3d18d694b99a85007f1cdbd_133
  135. CGPoint.make, and we shall do

    Segment details8:25–8:29 · rev_9e1406cad3d18d694b99a85007f1cdbd_134
  136. label— whoops— label.center

    Segment details8:30–8:33 · rev_9e1406cad3d18d694b99a85007f1cdbd_135
  137. Oh, we've done label wrong. It should be

    Segment details8:35–8:37 · rev_9e1406cad3d18d694b99a85007f1cdbd_136
  138. capital L.

    Segment details8:37–8:37 · rev_9e1406cad3d18d694b99a85007f1cdbd_137
  139. I spelled it wrong. No, it's not

    Segment details8:42–8:45 · rev_9e1406cad3d18d694b99a85007f1cdbd_138
  140. capital L.

    Segment details8:45–8:46 · rev_9e1406cad3d18d694b99a85007f1cdbd_139
  141. Yeah,

    Segment details8:48–8:48 · rev_9e1406cad3d18d694b99a85007f1cdbd_140
  142. .center.x and then

    Segment details8:50–8:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_141
  143. label.center.y, close brackets

    Segment details8:54–8:58 · rev_9e1406cad3d18d694b99a85007f1cdbd_142
  144. and then semicolon. Now we want it to move

    Segment details8:58–9:00 · rev_9e1406cad3d18d694b99a85007f1cdbd_143
  145. to the right, so So we go on the

    Segment details9:00–9:03 · rev_9e1406cad3d18d694b99a85007f1cdbd_144
  146. x-coordinate and we should do— is

    Segment details9:03–9:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_145
  147. it plus? So let's do +10,

    Segment details9:07–9:08 · rev_9e1406cad3d18d694b99a85007f1cdbd_146
  148. and then let's see if it works.

    Segment details9:11–9:13 · rev_9e1406cad3d18d694b99a85007f1cdbd_147
  149. There it goes, it's moving! Yeah, we did

    Segment details9:22–9:24 · rev_9e1406cad3d18d694b99a85007f1cdbd_148
  150. it! Okay. So let's

    Segment details9:24–9:28 · rev_9e1406cad3d18d694b99a85007f1cdbd_149
  151. close this simulator. Now I want simulator

    Segment details9:28–9:32 · rev_9e1406cad3d18d694b99a85007f1cdbd_150
  152. on— that's fine. Close simulator.

    Segment details9:32–9:35 · rev_9e1406cad3d18d694b99a85007f1cdbd_151
  153. Then go back to tutorial. Okay, so we want

    Segment details9:38–9:42 · rev_9e1406cad3d18d694b99a85007f1cdbd_152
  154. the label to keep reappearing

    Segment details9:43–9:46 · rev_9e1406cad3d18d694b99a85007f1cdbd_153
  155. on the screen after it's disappeared. So

    Segment details9:46–9:49 · rev_9e1406cad3d18d694b99a85007f1cdbd_154
  156. how do we do that? Well, we do an if

    Segment details9:49–9:52 · rev_9e1406cad3d18d694b99a85007f1cdbd_155
  157. statement. If label.center

    Segment details9:52–9:56 · rev_9e1406cad3d18d694b99a85007f1cdbd_156
  158. equals— no, if label.x equal

    Segment details9:56–10:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_157
  159. is greater than— greater

    Segment details10:01–10:06 · rev_9e1406cad3d18d694b99a85007f1cdbd_158
  160. than what? Greater than— off the edge of

    Segment details10:07–10:11 · rev_9e1406cad3d18d694b99a85007f1cdbd_159
  161. the screen should be like 256

    Segment details10:11–10:15 · rev_9e1406cad3d18d694b99a85007f1cdbd_160
  162. 3. So look at the X here. So 320.

    Segment details10:20–10:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_161
  163. So if it's greater than 320, it should

    Segment details10:26–10:29 · rev_9e1406cad3d18d694b99a85007f1cdbd_162
  164. reappear at -100.

    Segment details10:29–10:33 · rev_9e1406cad3d18d694b99a85007f1cdbd_163
  165. 320 and -100.

    Segment details10:35–10:37 · rev_9e1406cad3d18d694b99a85007f1cdbd_164
  166. Okay, so go back to game or something. M.

    Segment details10:38–10:40 · rev_9e1406cad3d18d694b99a85007f1cdbd_165
  167. If it's greater than 320 Then

    Segment details10:40–10:46 · rev_9e1406cad3d18d694b99a85007f1cdbd_166
  168. we shall make it label.center equals

    Segment details10:46–10:50 · rev_9e1406cad3d18d694b99a85007f1cdbd_167
  169. CGPoint make,

    Segment details10:51–10:52 · rev_9e1406cad3d18d694b99a85007f1cdbd_168
  170. and then press Enter, and then do— do—

    Segment details10:54–10:58 · rev_9e1406cad3d18d694b99a85007f1cdbd_169
  171. what was it?

    Segment details10:58–10:59 · rev_9e1406cad3d18d694b99a85007f1cdbd_170
  172. Can't remember. -100, see,

    Segment details11:02–11:06 · rev_9e1406cad3d18d694b99a85007f1cdbd_171
  173. and then I think this can be 0.

    Segment details11:06–11:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_172
  174. No, it should be 200.

    Segment details11:12–11:13 · rev_9e1406cad3d18d694b99a85007f1cdbd_173
  175. Whoops. Okay, click on my label.

    Segment details11:15–11:18 · rev_9e1406cad3d18d694b99a85007f1cdbd_174
  176. It was -100 and y-axis was 200.

    Segment details11:20–11:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_175
  177. Should be 200.

    Segment details11:26–11:33 · rev_9e1406cad3d18d694b99a85007f1cdbd_176
  178. So if label.x is greater than 320,

    Segment details11:34–11:36 · rev_9e1406cad3d18d694b99a85007f1cdbd_177
  179. labelAtCenter CGPoint.make, and this

    Segment details11:37–11:40 · rev_9e1406cad3d18d694b99a85007f1cdbd_178
  180. should keep repeating over and over.

    Segment details11:40–11:44 · rev_9e1406cad3d18d694b99a85007f1cdbd_179
  181. That's it. Yep, it keeps reappearing.

    Segment details11:51–11:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_180
  182. Okay, simulator, where are you?

    Segment details11:54–11:55 · rev_9e1406cad3d18d694b99a85007f1cdbd_181
  183. Ah, doesn't matter. Anyway, it was a bit

    Segment details11:57–11:59 · rev_9e1406cad3d18d694b99a85007f1cdbd_182
  184. too close on the left side of the screen,

    Segment details12:00–12:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_183
  185. so let's change this to 400.

    Segment details12:02–12:04 · rev_9e1406cad3d18d694b99a85007f1cdbd_184
  186. So there it goes off the screen and

    Segment details12:11–12:12 · rev_9e1406cad3d18d694b99a85007f1cdbd_185
  187. reappears.

    Segment details12:12–12:13 · rev_9e1406cad3d18d694b99a85007f1cdbd_186
  188. Okay, let's just minimize this. And this—

    Segment details12:16–12:18 · rev_9e1406cad3d18d694b99a85007f1cdbd_187
  189. oh, look at all this crap. Can we move

    Segment details12:18–12:22 · rev_9e1406cad3d18d694b99a85007f1cdbd_188
  190. this? Move it here? Why can't I move it?

    Segment details12:22–12:25 · rev_9e1406cad3d18d694b99a85007f1cdbd_189
  191. Okay, let's just close it, quit,

    Segment details12:31–12:33 · rev_9e1406cad3d18d694b99a85007f1cdbd_190
  192. and run it again. No, why are

    Segment details12:35–12:38 · rev_9e1406cad3d18d694b99a85007f1cdbd_191
  193. you on the left side? I don't want you on

    Segment details12:38–12:40 · rev_9e1406cad3d18d694b99a85007f1cdbd_192
  194. this screen.

    Segment details12:40–12:40 · rev_9e1406cad3d18d694b99a85007f1cdbd_193
  195. We could— hold

    Segment details12:46–12:50 · rev_9e1406cad3d18d694b99a85007f1cdbd_194
  196. on. So where were we?

    Segment details12:50–12:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_195
  197. So the simulator is moving the label. So

    Segment details12:53–12:56 · rev_9e1406cad3d18d694b99a85007f1cdbd_196
  198. we want a— we

    Segment details12:56–13:01 · rev_9e1406cad3d18d694b99a85007f1cdbd_197
  199. need to make our buttons work for pause

    Segment details13:02–13:03 · rev_9e1406cad3d18d694b99a85007f1cdbd_198
  200. and resume. Okay, so go into .m and

    Segment details13:03–13:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_199
  201. we do like this, baby action, and put

    Segment details13:07–13:10 · rev_9e1406cad3d18d694b99a85007f1cdbd_200
  202. pause. Get rid of this

    Segment details13:10–13:14 · rev_9e1406cad3d18d694b99a85007f1cdbd_201
  203. extra stuff and then open curly brackets.

    Segment details13:14–13:17 · rev_9e1406cad3d18d694b99a85007f1cdbd_202
  204. And what we want here is when you press

    Segment details13:17–13:20 · rev_9e1406cad3d18d694b99a85007f1cdbd_203
  205. pause, it does invalidate.

    Segment details13:20–13:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_204
  206. So we need labelTimer and then invalidate,

    Segment details13:24–13:27 · rev_9e1406cad3d18d694b99a85007f1cdbd_205
  207. and that should be all. So when you press

    Segment details13:29–13:32 · rev_9e1406cad3d18d694b99a85007f1cdbd_206
  208. pause, it should stop.

    Segment details13:32–13:34 · rev_9e1406cad3d18d694b99a85007f1cdbd_207
  209. There, it stops. So how do we restart it?

    Segment details13:36–13:39 · rev_9e1406cad3d18d694b99a85007f1cdbd_208
  210. That's easy. We do IBAction and

    Segment details13:39–13:44 · rev_9e1406cad3d18d694b99a85007f1cdbd_209
  211. we type in resume.

    Segment details13:44–13:45 · rev_9e1406cad3d18d694b99a85007f1cdbd_210
  212. And then we do just copy and paste your

    Segment details13:49–13:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_211
  213. timer code into here,

    Segment details13:54–13:56 · rev_9e1406cad3d18d694b99a85007f1cdbd_212
  214. and then should work.

    Segment details14:01–14:03 · rev_9e1406cad3d18d694b99a85007f1cdbd_213
  215. Pause, resume, pause,

    Segment details14:05–14:08 · rev_9e1406cad3d18d694b99a85007f1cdbd_214
  216. resume. So what you could use this for is

    Segment details14:08–14:11 · rev_9e1406cad3d18d694b99a85007f1cdbd_215
  217. imagine if you had a game and these were

    Segment details14:11–14:13 · rev_9e1406cad3d18d694b99a85007f1cdbd_216
  218. like characters moving. On the timer.

    Segment details14:13–14:15 · rev_9e1406cad3d18d694b99a85007f1cdbd_217
  219. And so if you press pause, it stops the

    Segment details14:16–14:18 · rev_9e1406cad3d18d694b99a85007f1cdbd_218
  220. timer, and then if you press resume, it

    Segment details14:18–14:21 · rev_9e1406cad3d18d694b99a85007f1cdbd_219
  221. runs the code for the timer again, so it

    Segment details14:21–14:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_220
  222. starts moving again. So it's quite easy,

    Segment details14:24–14:26 · rev_9e1406cad3d18d694b99a85007f1cdbd_221
  223. quite simple to get your head around. All

    Segment details14:26–14:29 · rev_9e1406cad3d18d694b99a85007f1cdbd_222
  224. you need to do is declare these buttons

    Segment details14:29–14:31 · rev_9e1406cad3d18d694b99a85007f1cdbd_223
  225. and then make an NSTimer, and then do a

    Segment details14:32–14:34 · rev_9e1406cad3d18d694b99a85007f1cdbd_224
  226. void for label movement, and then

    Segment details14:35–14:37 · rev_9e1406cad3d18d694b99a85007f1cdbd_225
  227. IBActions for pause and resume.

    Segment details14:38–14:40 · rev_9e1406cad3d18d694b99a85007f1cdbd_226
  228. Pretty simple. And then link them up.

    Segment details14:42–14:45 · rev_9e1406cad3d18d694b99a85007f1cdbd_227
  229. Make sure they're all linked up like this.

    Segment details14:47–14:48 · rev_9e1406cad3d18d694b99a85007f1cdbd_228
  230. So you can see linked up stuff. See, this

    Segment details14:50–14:53 · rev_9e1406cad3d18d694b99a85007f1cdbd_229
  231. is linked up, received actions, and these

    Segment details14:53–14:55 · rev_9e1406cad3d18d694b99a85007f1cdbd_230
  232. are outlets. So yeah, pretty simple.

    Segment details14:55–14:59 · rev_9e1406cad3d18d694b99a85007f1cdbd_231
  233. Hope it helps you. If you have any

    Segment details15:00–15:02 · rev_9e1406cad3d18d694b99a85007f1cdbd_232
  234. questions, just ask me and I'll try, but

    Segment details15:02–15:05 · rev_9e1406cad3d18d694b99a85007f1cdbd_233
  235. I'm still new to coding. So I'm just

    Segment details15:05–15:07 · rev_9e1406cad3d18d694b99a85007f1cdbd_234
  236. trying to teach you what I know already.

    Segment details15:08–15:09 · rev_9e1406cad3d18d694b99a85007f1cdbd_235
  237. So don't think I'm like some kind of

    Segment details15:10–15:12 · rev_9e1406cad3d18d694b99a85007f1cdbd_236
  238. expert because I'm not. I only started

    Segment details15:12–15:14 · rev_9e1406cad3d18d694b99a85007f1cdbd_237
  239. about 2 weeks ago. So yeah, coding isn't

    Segment details15:15–15:18 · rev_9e1406cad3d18d694b99a85007f1cdbd_238
  240. that difficult, I guess, like for the

    Segment details15:18–15:20 · rev_9e1406cad3d18d694b99a85007f1cdbd_239
  241. basic stuff. Anyway, see you in the next

    Segment details15:20–15:23 · rev_9e1406cad3d18d694b99a85007f1cdbd_240
  242. video.

    Segment details15:23–15:24 · rev_9e1406cad3d18d694b99a85007f1cdbd_241