Skip to content

Commit e47395d

Browse files
author
Paige Plander
committed
moving around files
1 parent 4eb420f commit e47395d

36 files changed

+146
-0
lines changed

[email protected]

18.2 KB
Loading

Drummer/Drummer.xcodeproj/project.pbxproj Drummer.xcodeproj/project.pbxproj

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
6C9C24E41E29B3D600D962E2 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 6C9C24E31E29B3D600D962E2 /* [email protected] */; };
1011
6CAB23901E29AF7100BA9DD3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CAB238F1E29AF7100BA9DD3 /* AppDelegate.swift */; };
1112
6CAB23951E29AF7100BA9DD3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6CAB23931E29AF7100BA9DD3 /* Main.storyboard */; };
1213
6CAB23971E29AF7100BA9DD3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CAB23961E29AF7100BA9DD3 /* Assets.xcassets */; };
@@ -29,6 +30,7 @@
2930
/* End PBXBuildFile section */
3031

3132
/* Begin PBXFileReference section */
33+
6C9C24E31E29B3D600D962E2 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
3234
6CAB238C1E29AF7100BA9DD3 /* Drummer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Drummer.app; sourceTree = BUILT_PRODUCTS_DIR; };
3335
6CAB238F1E29AF7100BA9DD3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3436
6CAB23941E29AF7100BA9DD3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
@@ -66,6 +68,7 @@
6668
6CAB23831E29AF7100BA9DD3 = {
6769
isa = PBXGroup;
6870
children = (
71+
6C9C24E31E29B3D600D962E2 /* [email protected] */,
6972
6CAB238E1E29AF7100BA9DD3 /* Drummer */,
7073
6CAB238D1E29AF7100BA9DD3 /* Products */,
7174
);
@@ -229,6 +232,7 @@
229232
6CAB23BD1E29B05200BA9DD3 /* drumkit1-1.wav in Resources */,
230233
6CAB23B61E29B05200BA9DD3 /* drumkit0-1.wav in Resources */,
231234
6CAB23B81E29B05200BA9DD3 /* drumkit0-3.wav in Resources */,
235+
6C9C24E41E29B3D600D962E2 /* [email protected] in Resources */,
232236
6CAB23BE1E29B05200BA9DD3 /* drumkit1-2.wav in Resources */,
233237
6CAB23C01E29B05200BA9DD3 /* drumkit1-4.wav in Resources */,
234238
6CAB23971E29AF7100BA9DD3 /* Assets.xcassets in Resources */,
@@ -403,6 +407,7 @@
403407
6CAB23A01E29AF7100BA9DD3 /* Release */,
404408
);
405409
defaultConfigurationIsVisible = 0;
410+
defaultConfigurationName = Release;
406411
};
407412
/* End XCConfigurationList section */
408413
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

README-images/endProduct.png

224 KB
Loading

README-images/overview.gif

331 KB
Loading

README-images/part2-1.png

961 KB
Loading

README-images/part2-2.png

731 KB
Loading

README-images/part2-3.png

811 KB
Loading

README-images/part4-2.png

1.07 MB
Loading

README-images/part4-3.png

886 KB
Loading

README.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# iOS DeCal - Lab 2 (AutoLayout) #
2+
3+
In today's lab, we'll be creating a responsive UI for a simple drum pad app using AutoLayout.
4+
5+
![alt text](/README-images/overview.gif)
6+
7+
8+
To get started, first clone this repository onto your own computer
9+
`git clone https://github.com/iosdecal/ios-decal-lab2`
10+
11+
Open the file `Drummer.xcodeproj` to start the lab.
12+
13+
## Part 1 - Getting Started ##
14+
Once you have opened the project in Xcode, notice the files present in the Navigator.
15+
16+
### Files we have provided ###
17+
We have provided the following files for you to use.
18+
19+
1. `Drumkit.swift` in the `Model` folder - this file contains the "brains" of our app, including the filenames for the audio files that we'll be using, as well as a method for playing these audio files.
20+
2.`DrummerViewController.swift` in the `Controller` folder - this file contains the ViewController class that will connect our View created in Interface Builder to our Model. You will be adding code to this file in this lab.
21+
3. `Main.storyboard` in the `View` folder - this is where you will be creating your UI elements (buttons, labels, etc) and AutoLayout Constraints. This file is automatically created for you each time you start a new Xcode project.
22+
4. `Assets.xcassets` in the `View` folder - contains all of the images used in the app (we have only included app icon images, but if you'd like to add your own images to customize the app, add them here). This is another file that is automatically created for you each time you create a new Xcode project.
23+
5. `Supporting Files` - contains all the audio clips we'll be using, as well as some other files we won't be using in today's lab (Ask a lab assistant if you want to learn about them!)
24+
25+
Once you've become familiar with the files in our app, open Interface Builder (`Main.storyboard`).
26+
27+
## Part 2 - Adding UI Elements to the View ##
28+
We have a total of 7 drum sounds per drum kit provided, so we'll need to create 7 UI Buttons in our storyboard.
29+
30+
Once you open your storyboard file, drag one 'Button' out from the `Object library` onto your empty View.
31+
32+
![alt text](/README-images/part2-1.png)
33+
34+
35+
You can edit how the button looks by open the `Attributes Inspector`, which can be found in the Utilities sidebar to the left side of the screen. Feel free to customize the button as much as you want, but at minimum, change out the background color so that the buttons are easy to see.
36+
37+
**Once you complete one button, create 6 others, and add them to your view in the following arrangement.** Since we want each button to play a unique sound, **give each button a unique integer tag from 0 to 7 (you can change a button's tag value using the Attributes Inspector**)
38+
39+
![alt text](/README-images/part2-2.png)
40+
41+
42+
Before we start adding constraints, let's add two more UI elements.
43+
**Add one Label and one Segmented Control to the bottom of your view**. These can both be found in the Object Library. We'll use these to switch between drum kits (different drum kits will have different sound files associated with them).
44+
45+
To clarify what the segmented control will be used for **Edit your UI Label to display "Drum Kit Type", and change the values of your Segmented Control to "Acoustic" and "Electronic"**
46+
47+
Your view should now look something like this:
48+
![alt text](/README-images/part2-3.png)
49+
50+
51+
Try building your project now by pressing `Command + B` or the "Run" button at the top left corner of Xcode. You'll see that the UI looks different than it does in the Interface builder, and that there is a lot of extra white space. You can rotate the simulator by pressing `Hardware > Rotate` to reveal some more UI issues. To fix these problems, we will use AutoLayout!
52+
53+
## Part 3 - Creating AutoLayout Constraints ##
54+
55+
For our app, we want to minimize the amount of whitespace by making the buttons as large as they possibly can be given the size of our screen. Instead of hard-coding in values for our buttons, we'll create constraints between each UI element.
56+
57+
To refresh your memory , you can create constraints in Storyboard by first clicking on a UI element, holding down `Control` and then dragging your cursor to another UI element or view. To fine-tune your constraints, open the `Size Inspector` in the `Utilities` pane. Scroll downwards to view all constraints on your UI element.
58+
59+
**You may add as many or as few constraints as you wish, but you must ensure the following to get credit for this lab:**
60+
61+
1. Every button should stretch in width and height to fill the entire screen (no hardcoded values for height and width!)
62+
2. All buttons must have the same height
63+
3. The first 6 buttons should have the same width and height
64+
4. The spacing (horizontal and vertical) between each button must be equal
65+
5. The label and the segmented control should remain the same height, regardless of screen size (Constrain their heights to a certain value).
66+
67+
**Use the image below as a guide to make sure that you made your constraints correctly.** Even though the screenshot only shows the UI for an iPhone 7, your app's UI elements should resize for any device size).
68+
69+
![alt text](/README-images/endProduct.png)
70+
71+
You are free to customize your UI however you'd like, as long as the constraint requirements listed above are satisfied.
72+
73+
**If you're stuck at this step and want a more detailed walkthrough, you can find a step-by-step guide of adding constraints for this lab [here][id].**
74+
75+
[id]: https://github.com/paigeplan/lab2-autolayout-guide "AutoLayout Guide"
76+
77+
## Part 4 - Connecting the View to the Model via a ViewController ##
78+
79+
Now that you've finished the UI, we can now connect our View to our Model. (Note: this portion of the lab is much shorter - you're almost done!)
80+
81+
### a. Creating Outlets for the Drum Buttons in DrummerViewController.swift ###
82+
83+
Now we can start connecting the UI elements we created in our Storyboard to our ViewController file so we can edit them programmatically.
84+
85+
**Open the Assistant Editor so that `Main.storyboard` and `DrummerViewController.swift` are both open.** "DrummerViewController" is the custom controller class associated with the view in `Main.storyboard`. Usually, you will have to set each of your ViewController's custom classes in the Identity Inspector in Interface Builder on your own, but we have done this step for you.
86+
87+
Since we wan't our drum pad buttons to play an audio clip when pressed, we'll want to create an *action* in our ViewController for each button.
88+
89+
To do this, **highlight all 7 buttons in your Storyboard, then Control + Drag from them into `DrummerViewController.swift`. The Connection should be an *Action*, the sender type should be set to *UIButton*, and the function name should be set to "drumButtonWasPressed"** (see image below).
90+
91+
![alt text](/README-images/part4-2.png)
92+
93+
To check that all your buttons were successfully connected to the IBAction, hover over the small circle next to "drumButtonWasPressed" in DrummerViewController.swift. All 7 buttons should appear highlighted in your Storyboard. If they aren't all highlighted, **click the small icon next to your IBAction "drumButtonWasPressed", and drag from it to each unhighlighted button to connect them** (see image below).
94+
95+
![alt text](/README-images/part4-3.png)
96+
97+
98+
### b. Adding Sound to our App ###
99+
100+
Now we have an action method that will be called any time a user taps one of the drum buttons. As of now, nothing will happen. Since we want a drum sound to be played each time a user taps a button, we'll need to add some code to this action method.
101+
102+
Luckily for you, this code has been implemented already in `Drummer.swift`, so simply **add the following code to your function "drumButtonWasPressed".**
103+
104+
@IBAction func drumButtonWasPressed(_ sender: UIButton) {
105+
currentDrumKit?.playDrumSound(forDrumWithTag: sender.tag)
106+
}
107+
108+
This line of code calls the method "playDrumSound" for the currently selected drum kit. Each drum button will play a different sound based off of the button's tag number, which is accessed using "sender.tag". (Open up `DrumKit.swift` if you want more information).
109+
110+
**Run your application and try pressing the drum buttons. Each button should play a different sound clip.** If all buttons play the same sound clip, make sure you set the "Tag" property for each button correctly in Part 2.
111+
112+
113+
### c. Adding Option to Switch between Drum Kits (OPTIONAL) ###
114+
115+
Right now, we can't switch between drum kits (tapping on the segmented control doesn't change anything). To fix this **create an IBAction in DrummerViewController.swift for the Segmented Control in the same way as done in Part 4a. Set the sender type to UISegmentedControl** You can name the method whatever you like, but we'll call it "drumKitWasChanged".
116+
117+
Note: If you an error saying "Could not find any information for class named DrummerViewController," you can manually type in the IBAction method in `DrummerViewController.swift`, then Click + drag from the action to the Segmented Control in your storyboard (copy and paste the code below for "drumKitWasChanged", then make the connection).
118+
119+
120+
You should now have the following method in `DrummerViewController.swift`:
121+
122+
@IBAction func drumKitWasChanged(_ sender: UISegmentedControl) { }
123+
124+
**Fill in this method to allow the user to switch between drum kits by updating the "currentDrumKit" variable.** Hint: you'll want to use your UISegmentedControl property "selectedSegmentIndex", which you can access using "sender.selectedSegmentIndex"
125+
126+
If you implemented the method correctly, tapping on the Segmented Control in your app should change the sound of each drum button.
127+
128+
## Grading ##
129+
130+
You have the option to either be checked off by a TA or instructor during lab to receive your grade immediately, or submit your files to [Gradescope][id] to be graded later.
131+
132+
[id]: https://gradescope.com/courses/5482/assignments/18748/ "Gradescope link"
133+
134+
If you are submitting via Gradescope, you will need to submit a zip folder of all of your project files (compress and submit the folder you cloned from GitHub).
135+
136+
We will grade your work based off the following criteria (all requirements must be satisfied to receive credit)
137+
138+
1. All buttons and UI elements must dynamically change as shown in the preview gif for any device size and orientation (use the image in part 3 as a guide for how your app should look).
139+
2. Tapping on a drum button must play a sound (your app needs to work!)
140+
141+
If both requirements are satisfied, congratulations on finishing Lab 2! :)

0 commit comments

Comments
 (0)