-
Peek and Pop 코드앱등이에게 살충제를 뿌린다./일기는 일기장에 2017. 6. 6. 17:40
<Like or Like>
ViewController.swift
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 charactersimport UIKit class ViewController: UIViewController { @IBOutlet weak var collectionView: UICollectionView! var photos: [UIImage] { var photoList: [UIImage] = [] for index in 0..<9 { let image = UIImage(named: "\(index).jpg") photoList.append(image!) } return photoList } override func viewDidLoad() { super.viewDidLoad() navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) navigationController?.navigationBar.shadowImage = UIImage() if traitCollection.forceTouchCapability == .available { registerForPreviewing(with: self, sourceView: view) } } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let destination = segue.destination as? DetailViewController { destination.image = (sender as? CollectionViewCell)?.imageView.image } } } extension ViewController: UIViewControllerPreviewingDelegate { func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) { print("\(#function) called.") // showDetailViewController(viewControllerToCommit, sender: self) } func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { guard let indexPath = collectionView.indexPathForItem(at: location) else { return nil } guard let cell = collectionView.cellForItem(at: indexPath) as? CollectionViewCell else { return nil } guard let detailVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DetailViewController") as? DetailViewController else { return nil } detailVC.image = photos[indexPath.row] detailVC.preferredContentSize = CGSize(width: 0, height: 300) previewingContext.sourceRect = cell.frame return detailVC } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { } } extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return photos.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell", for: indexPath) as? CollectionViewCell else { return UICollectionViewCell() } cell.imageView.image = photos[indexPath.row] return cell } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: collectionView.bounds.size.width / 2.5, height: collectionView.bounds.size.height) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { return CGSize(width: 0, height: 0) } } class CollectionViewCell: UICollectionViewCell { @IBOutlet weak var imageView: UIImageView! } DetailViewController.swift
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 charactersimport UIKit class DetailViewController: UIViewController { var image: UIImage? @IBOutlet weak var imageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() imageView.image = image } override var previewActionItems: [UIPreviewActionItem] { let likeAction = UIPreviewAction(title: "Like", style: .default) { (action, viewController) in print("Like pressed. action: \(action), viewController: \(viewController)") } let deleteAction = UIPreviewAction(title: "Like", style: .destructive) { (action, viewController) in print("Delete pressed. action: \(action), viewController: \(viewController)") } return [likeAction, deleteAction] } } '앱등이에게 살충제를 뿌린다. > 일기는 일기장에' 카테고리의 다른 글
UITableView와 UICollectionView의 AutoSize에 관하여.. (0) 2017.06.17 [Diary] WWDC 2017 비디오를 보면서.. (0) 2017.06.08 [iOS/Swift/AVFoundation] 카메라를 붙이며 알게된 것, + 알아볼 것 (0) 2017.03.16 XCode의 The Basic of Unit Test - 유닛테스트 기본 (0) 2017.01.09 NSAttributedString, NSRange 를 부탁해 (1) 2016.12.20