tweaks to Project 3

This commit is contained in:
CypherPoet 2019-02-25 17:16:03 -05:00
parent e24686d968
commit 5fd45221a6
5 changed files with 46 additions and 48 deletions

View File

@ -6,6 +6,7 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@ -28,7 +29,7 @@
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="qem-fj-5MQ">
<rect key="frame" x="16" y="0.0" width="324" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
@ -63,7 +64,7 @@
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Sje-Uw-DS7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="40.799999999999997" y="-671.51424287856082"/>
<point key="canvasLocation" x="46" y="27"/>
</scene>
<!--Detail View Controller-->
<scene sceneID="oIt-cV-HL4">
@ -84,6 +85,7 @@
<constraint firstItem="XEW-Lo-AqF" firstAttribute="bottom" secondItem="GBY-9N-YdR" secondAttribute="bottom" id="rFn-Ho-Mml"/>
<constraint firstAttribute="trailing" secondItem="XEW-Lo-AqF" secondAttribute="trailing" id="tAb-Tf-8eg"/>
</constraints>
<viewLayoutGuide key="safeArea" id="2gv-9e-Yej"/>
</view>
<connections>
<outlet property="imageView" destination="XEW-Lo-AqF" id="XzE-xQ-8al"/>

View File

@ -11,30 +11,31 @@ import UIKit
class DetailViewController: UIViewController {
@IBOutlet var imageView: UIImageView!
var selectedImagePath: String?
var imagePath: String!
var imageNumber: Int!
var totalImageCount: Int!
var imageName: String {
if let index = imagePath.firstIndex(of: ".") {
return String(imagePath.prefix(upTo: index))
} else {
return imagePath
}
}
override var prefersHomeIndicatorAutoHidden: Bool {
get {
return navigationController?.hidesBarsOnTap ?? false
}
}
override func viewDidLoad() {
super.viewDidLoad()
title = selectedImagePath
navigationItem.largeTitleDisplayMode = .never
navigationItem.rightBarButtonItem = UIBarButtonItem(
barButtonSystemItem: .action,
target: self,
action: #selector(shareTapped)
)
if let _imagePath = selectedImagePath {
imageView.image = UIImage(named: _imagePath)
}
setupNavbar()
imageView.image = UIImage(named: imagePath)
}
@ -44,33 +45,35 @@ class DetailViewController: UIViewController {
navigationController?.hidesBarsOnTap = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.hidesBarsOnTap = false
}
// MARK: - Helper functions
func setupNavbar() {
title = "Picture \(imageNumber!) of \(totalImageCount!)"
navigationItem.largeTitleDisplayMode = .never
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareButtonTapped))
}
@objc func shareTapped() {
let controller = UIActivityViewController(
activityItems: [imageView.image!],
applicationActivities: []
)
// MARK: - Event handlers
@objc func shareButtonTapped() {
guard let imageData = imageView.image?.jpegData(compressionQuality: 0.8) else {
print("No image data found")
return
}
// tell iOS where the controller should be anchored
controller.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
let viewController = UIActivityViewController(activityItems: [imageData, imageName], applicationActivities: nil)
present(controller, animated: true)
viewController.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem
present(viewController, animated: true)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}

View File

@ -34,8 +34,6 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>We&apos;d like to save photos you like to your library</string>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>

View File

@ -2,15 +2,12 @@
// ViewController.swift
// Storm Viewer
//
// Created by Brian Sipple on 1/10/19.
// Copyright © 2019 Brian Sipple. All rights reserved.
//
import UIKit
class ViewController: UITableViewController {
var imagePaths = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
@ -22,7 +19,7 @@ class ViewController: UITableViewController {
let images = try! fm.contentsOfDirectory(atPath: path)
imagePaths = images.filter({ $0.hasPrefix("nssl") })
imagePaths = images.filter({ $0.hasPrefix("nssl") }).sorted()
}
@ -41,13 +38,11 @@ class ViewController: UITableViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// try loading the "Detail" view controller and typecasting it to be DetailViewController
if let detailViewController = storyboard?.instantiateViewController(withIdentifier: "Image Detail") as? DetailViewController {
// set the vc's `imagePath` property to match the image selected
detailViewController.selectedImagePath = imagePaths[indexPath.row]
detailViewController.imagePath = imagePaths[indexPath.row]
detailViewController.imageNumber = indexPath.row + 1
detailViewController.totalImageCount = imagePaths.count
// push the detail VC onto the navigation controller
navigationController?.pushViewController(detailViewController, animated: true)
}
}

View File

@ -56,7 +56,7 @@
| :--: | :-------------------------: | :--------------: | :--------: |
| 31 | 📱<br>[Multibrowser](/31-multibrowser) | UIStackView, iPad multitasking, addArrangedSubview(), WKNavigationDelegate, UITextFieldDelegate, UIGestureRecognizerDelegate, App Transport Security, Adaptive UI (Size Classes and Dynamic Type), using `StackView.removeArrangedSubview` alongside `WKWebView.removeFromSuperview` | ✅ |
| 32 | 📱<br>[Swift Searcher](/32-swift-searcher) | Dynamic Type, NSAttributedString, SFSafariViewController, SFSafariViewControllerDelegate, Core Spotlight, UIContentSizeCategoryDidChange, responding to the `CSSearchableItemActionType` activity during app startup to handle CoreSpotlight search hits | ✅ |
| 33 | 📱<br>[Name That Tune](/33-name-that-tune) | All about CloudKit ☁️: loading and saving text data, loading and saving binary data, registering for updates, delivering push messages, and more; AVAudioRecorder; AVAudioSession; requestRecordPermission(); CKRecord; CKAsset; CloudKit Dashboard; CKQueryOperation; NSPredicate; CKRecord.Reference; fetch(withRecordID:); save(); CKQuerySubscription; NSSortDescriptor | 🚧 |
| 33 | 📱<br>[Name That Tune](/33-name-that-tune) | All about CloudKit ☁️: loading and saving text data, loading and saving binary data, registering for updates, delivering push messages, CloudKit Dashboard and more; AVAudioRecorder; AVAudioSession; requestRecordPermission(); CKRecord; CKAsset; CKQueryOperation; NSPredicate; CKRecord.Reference; fetch(withRecordID:); save(); CKQuerySubscription; NSSortDescriptor | 🚧 |
| 34 | 🎮<br>[Four in a Row](/34-connect-four) | GameplayKit AI, GKGameModel, GKGameModelPlayer, GKGameModelUpdate, AI Heuristics, NSCopying, GKMinmaxStrategist | 🔴 |
| 35 | 🛠<br>[Random Numbers](/35-Random-Numbers) | Int.random(in:), Float.random(in:), Double.random(in:), CGFloat.random(in:), Bool.random(), arc4random(), GKRandomSource.sharedRandom(), GKLinearCongruentialRandomSource, GKMersenneTwisterRandomSource, GKARC4RandomSource, GKRandomDistribution, GKShuffledDistribution, GKGaussianDistribution, Fisher-Yates Algorithm, arrayByShufflingObjects(in:) | 🔴 |
| 36 | 🎮<br>[Crashy Plane](/36-crashy-plane) | Composed Methods, Scale Modes, Parallax Scrolling, SpriteKit Physics, SKPhysicsContactDelegate, SKPhysicsBody, SKAudioNode, Managing Game State | 🔴 |