Skip to content

Commit

Permalink
click on collection view image to show it full screen / double tap to…
Browse files Browse the repository at this point in the history
… dismiss
  • Loading branch information
johnnyperdomo committed Mar 21, 2018
1 parent 0933b38 commit 0987adf
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pixel-city.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
FE14F0B1203F93E800B0A428 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FE14F0AF203F93E800B0A428 /* Main.storyboard */; };
FE14F0B3203F93E800B0A428 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FE14F0B2203F93E800B0A428 /* Assets.xcassets */; };
FE14F0B6203F93E800B0A428 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FE14F0B4203F93E800B0A428 /* LaunchScreen.storyboard */; };
FE26A6332061E8790051E2F2 /* PopVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE26A6322061E8790051E2F2 /* PopVC.swift */; };
FE95EA8C2059D4EA000176E7 /* DroppablePin.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE95EA8B2059D4EA000176E7 /* DroppablePin.swift */; };
FEA4E3DF205E074900D45C96 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEA4E3DE205E074900D45C96 /* Constants.swift */; };
FEA83034205D859C00C489F5 /* PhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEA83033205D859C00C489F5 /* PhotoCell.swift */; };
Expand All @@ -29,6 +30,7 @@
FE14F0B2203F93E800B0A428 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
FE14F0B5203F93E800B0A428 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
FE14F0B7203F93E800B0A428 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FE26A6322061E8790051E2F2 /* PopVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopVC.swift; sourceTree = "<group>"; };
FE95EA8B2059D4EA000176E7 /* DroppablePin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DroppablePin.swift; sourceTree = "<group>"; };
FEA4E3DE205E074900D45C96 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
FEA83033205D859C00C489F5 /* PhotoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -101,6 +103,7 @@
isa = PBXGroup;
children = (
FE14F0AD203F93E800B0A428 /* MapVC.swift */,
FE26A6322061E8790051E2F2 /* PopVC.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -260,6 +263,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FE26A6332061E8790051E2F2 /* PopVC.swift in Sources */,
FEA4E3DF205E074900D45C96 /* Constants.swift in Sources */,
FEA83034205D859C00C489F5 /* PhotoCell.swift in Sources */,
FE14F0AE203F93E800B0A428 /* MapVC.swift in Sources */,
Expand Down
49 changes: 49 additions & 0 deletions pixel-city/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,55 @@
</objects>
<point key="canvasLocation" x="117.59999999999999" y="118.29085457271366"/>
</scene>
<!--PopVC-->
<scene sceneID="mDF-Lg-44M">
<objects>
<viewController storyboardIdentifier="PopVC" id="p3w-lK-cik" customClass="PopVC" customModule="pixel_city" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Xrd-yu-ERG">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="4jC-Ao-kPQ">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xoM-fd-IBR">
<rect key="frame" x="87" y="622" width="200" height="25"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Double Tap To Dismiss" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IJf-wl-e3E">
<rect key="frame" x="11.5" y="1" width="177" height="23.5"/>
<fontDescription key="fontDescription" name="AvenirNext-DemiBold" family="Avenir Next" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="IJf-wl-e3E" firstAttribute="centerY" secondItem="xoM-fd-IBR" secondAttribute="centerY" id="20G-EZ-rii"/>
<constraint firstItem="IJf-wl-e3E" firstAttribute="centerX" secondItem="xoM-fd-IBR" secondAttribute="centerX" id="Mq1-WG-6lH"/>
<constraint firstAttribute="height" constant="25" id="Qme-uN-IsU"/>
<constraint firstAttribute="width" constant="200" id="eke-8G-I84"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="4jC-Ao-kPQ" firstAttribute="bottom" secondItem="T5j-xs-1ev" secondAttribute="bottom" id="LST-Bf-5ho"/>
<constraint firstItem="4jC-Ao-kPQ" firstAttribute="trailing" secondItem="T5j-xs-1ev" secondAttribute="trailing" id="OK1-Lw-Chn"/>
<constraint firstItem="4jC-Ao-kPQ" firstAttribute="top" secondItem="Xrd-yu-ERG" secondAttribute="top" id="S9n-ru-p6d"/>
<constraint firstItem="xoM-fd-IBR" firstAttribute="centerX" secondItem="Xrd-yu-ERG" secondAttribute="centerX" id="aMz-LJ-qOB"/>
<constraint firstItem="T5j-xs-1ev" firstAttribute="bottom" secondItem="xoM-fd-IBR" secondAttribute="bottom" constant="20" id="bwc-3t-rVq"/>
<constraint firstItem="4jC-Ao-kPQ" firstAttribute="leading" secondItem="T5j-xs-1ev" secondAttribute="leading" id="fyk-UN-GSW"/>
</constraints>
<viewLayoutGuide key="safeArea" id="T5j-xs-1ev"/>
</view>
<connections>
<outlet property="popImageView" destination="4jC-Ao-kPQ" id="sgE-gq-ViU"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="udf-Eo-GIz" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="786.39999999999998" y="116.49175412293854"/>
</scene>
</scenes>
<resources>
<image name="locationButton" width="67" height="67"/>
Expand Down
6 changes: 6 additions & 0 deletions pixel-city/Controller/MapVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ extension MapVC: UICollectionViewDelegate, UICollectionViewDataSource { //confor
return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { //when one of the cells is tapped or selected
guard let popVC = storyboard?.instantiateViewController(withIdentifier: "PopVC") as? PopVC else { return } //instance of popVC
popVC.initData(forImage: imageArray[indexPath.row]) //will send the exact image we tapped. index path.row
present(popVC, animated: true, completion: nil) //present it to the view controller
}

}


Expand Down
38 changes: 38 additions & 0 deletions pixel-city/Controller/PopVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// PopVC.swift
// pixel-city
//
// Created by Johnny Perdomo on 3/20/18.
// Copyright © 2018 Johnny Perdomo. All rights reserved.
//

import UIKit

class PopVC: UIViewController, UIGestureRecognizerDelegate {

@IBOutlet weak var popImageView: UIImageView!

var passedImage: UIImage! //the image that will be passed

func initData(forImage image: UIImage) { //pass in an image to initialize this VC
self.passedImage = image//the passed image will be the image
}

override func viewDidLoad() {
super.viewDidLoad()
popImageView.image = passedImage //this will make the image of the popVC be the passed image
addDoubleTap()
}


func addDoubleTap() {
let doubleTap = UITapGestureRecognizer(target: self, action: #selector(screenWasDoubleTapped))
doubleTap.numberOfTapsRequired = 2
doubleTap.delegate = self
view.addGestureRecognizer(doubleTap)
}

@objc func screenWasDoubleTapped() {
dismiss(animated: true, completion: nil) //to dismiss the view controller
}
}

0 comments on commit 0987adf

Please sign in to comment.