This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a simple Augmented Reality object with ARKit and SceneKit is surprisingly easy! But before you get started, you | |
// need to add a key-value pair to your application's Info.plist (Information Property List) file. Add the key "Privacy - | |
// Camera Usage Description" with the corresponding value "This application will use your camera for Augmented Reality", or | |
// some similarly descriptive note. | |
// Let's get started! | |
// You'll need to import SceneKit to create your object and ARKit to place it in your augmented reality space. | |
import UIKit | |
import SceneKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating a 3D text object with ARKit isn't overwhelming. It might not be immediately obvious, but these objects could | |
// be quite valuable moving forward. Imagine dropping a 3D advertisement in someone's augmented reality universe... | |
// We'll get started in a sec, but first you need to add a key-value pair to your application's Info.plist (Information | |
// Property List) file. Add the key "Privacy - Camera Usage Description" with the corresponding value "This application | |
// will use your camera for Augmented Reality", or some similarly descriptive note. | |
// Let's get started! | |
// You'll need to import SceneKit to create your object and ARKit to place it in your augmented reality space. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adding a second object to your Augmented Reality space is not much different from adding the first, so we will change | |
// things up here a bit. Here we will create a sphere in addition to a box and we will give our objects some style. | |
// If you haven't already, you need to add a key-value pair to your application's Info.plist (Information Property List) file. | |
// Add the key "Privacy - Camera Usage Description" with the corresponding value "This application will use your camera for | |
// Augmented Reality", or some similarly descriptive note. | |
// Let's get started! | |
// You'll need to import SceneKit to create and edit your objects and ARKit to place it in your augmented reality space. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using touch gestures to interact with your Augmented Reality objects actually doesn't involve more ARKit code! Rather, | |
// you'll have to implement some new SCNKit code and play with a UITapGestureRecognizer from good ol' UIKit. Here we will | |
// create a Super Mario box, and it will pop up as if you were Mario jumping underneath it! | |
// If you're jumping straight into this view controller, you might need to update your info.plist (Information Property | |
// List) file first. Add the key "Privacy - Camera Usage Description" with the corresponding value "This application will | |
// use your camera for Augmented Reality", or some similarly descriptive note. | |
// Let's get started! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The table views in this app actually don't make use of tableView(_:heightForRowAt:). These table views set the table views' | |
// rowHeight and estimatedRowHeight properties to UITableViewAutomaticDimension and 110, respectively, and they make use | |
// of a series of constraints to automatically set each cells' row height. | |
// Use tableView(_:heightForRowAt:) to set the height for specific table view cells. | |
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | |
// Set the row height for the first (zeroth) cell in all section(s) to 100, and set all other cells to 50. | |
// You can also set the row height for all cells in a section by accessing indexPath.section. | |
if indexPath.row == 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use tableView(_:didSelectRowAt:) to manage what happens when a user selects a UITableViewCell. | |
// This example exhibits how this app makes use of this method. | |
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
// Determine what to do when a cell in a particular section is selected. | |
switch indexPath.section { | |
case 0: | |
// If the cell in the first section is selected, this will trigger the segue with the "toHeightForRowAt" identifier | |
self.performSegue(withIdentifier: "toHeightForRowAt", sender: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use tableView(_:editActionsForRowAt:) to implement swipe actions for a UITableView's cells. | |
// This example exhibits how this app makes use of this method. | |
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { | |
// Get the title of each section to notify the user that a cell in a particular section was swiped. | |
let sectionHeaderView = tableView.headerView(forSection: indexPath.section) | |
let sectionTitle = sectionHeaderView?.textLabel?.text | |
// Create an action. Create custom actions in the UITableViewRowAction's closure. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use tableView(_:numberOfRowsInSection:) to determine the number of rows each section of a UITableView should display. | |
// This example exhibits how this app makes use of this method. | |
// Create some sort of data source. This is often an array or, in this case, a dictionary. | |
var dataSource: [String: String] { | |
return ["cellForRowAt: indexPath": "Update cell information based on the data source\nReturns a UITableViewCell.", | |
"numberOfRowsInSection: Int": "Determine the number of rows needed for each section of the tableView\nReturns an Int", | |
"titleForHeaderInSection: Int": "Set the title for a particular section of your tableView\nReturns a String"] | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use tableView(_:titleForHeaderInSection:) to set the title for each section in a table view. | |
// This example exhibits two instances of this method used in this app. | |
// This demonstrates the use of this method in this app's UITableViewDataSource view controller. | |
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | |
switch section { | |
case 0: | |
return "Configuring a Table View" | |
default: | |
print("out of index") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use tableView(_:cellForRowAt:) to customize the cells in a table view. | |
// This example demonstrates an instance of how one of this app's table views uses this method. | |
// Create some sort of data source. This is often an array or, in this case, a dictionary. | |
var dataSource: [String: String] { | |
return ["cellForRowAt: indexPath": "Update cell information based on the data source\nReturns a UITableViewCell.", | |
"numberOfRowsInSection: Int": "Determine the number of rows needed for each section of the tableView\nReturns an Int", | |
"titleForHeaderInSection: Int": "Set the title for a particular section of your tableView\nReturns a String"] | |
} |
OlderNewer