Commit a57103d1 authored by domenicw's avatar domenicw
Browse files

Finished Generic Info Controller and Added an Image Viewer Controller

parent 20ee26ed
......@@ -53,6 +53,8 @@
B0FE2F0621541C5C00F3D073 /* GenericInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F0521541C5C00F3D073 /* GenericInfoViewController.swift */; };
B0FE2F082154230500F3D073 /* GenericInfoViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F072154230500F3D073 /* GenericInfoViewControllerDelegate.swift */; };
B0FE2F0A2154237C00F3D073 /* GenericInfoViewControllerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F092154237C00F3D073 /* GenericInfoViewControllerModel.swift */; };
B0FE2F0D21543E6600F3D073 /* ImageViewerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F0C21543E6600F3D073 /* ImageViewerViewController.swift */; };
B0FE2F102154495100F3D073 /* BlurButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F0F2154495100F3D073 /* BlurButton.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -117,6 +119,8 @@
B0FE2F0521541C5C00F3D073 /* GenericInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericInfoViewController.swift; sourceTree = "<group>"; };
B0FE2F072154230500F3D073 /* GenericInfoViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericInfoViewControllerDelegate.swift; sourceTree = "<group>"; };
B0FE2F092154237C00F3D073 /* GenericInfoViewControllerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericInfoViewControllerModel.swift; sourceTree = "<group>"; };
B0FE2F0C21543E6600F3D073 /* ImageViewerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewerViewController.swift; sourceTree = "<group>"; };
B0FE2F0F2154495100F3D073 /* BlurButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlurButton.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -159,6 +163,7 @@
B050E11E215169230090CB79 /* Amiv */ = {
isa = PBXGroup;
children = (
B0FE2F0E2154494100F3D073 /* View */,
B050E15D215173470090CB79 /* Extension */,
B050E15721516E160090CB79 /* Model */,
B050E141215169740090CB79 /* View Controller */,
......@@ -451,6 +456,7 @@
B0FE2F0321541C3700F3D073 /* Generic */ = {
isa = PBXGroup;
children = (
B0FE2F0B21543E4B00F3D073 /* Image Viewer */,
B0FE2F0421541C4000F3D073 /* Info */,
);
path = Generic;
......@@ -466,6 +472,22 @@
path = Info;
sourceTree = "<group>";
};
B0FE2F0B21543E4B00F3D073 /* Image Viewer */ = {
isa = PBXGroup;
children = (
B0FE2F0C21543E6600F3D073 /* ImageViewerViewController.swift */,
);
path = "Image Viewer";
sourceTree = "<group>";
};
B0FE2F0E2154494100F3D073 /* View */ = {
isa = PBXGroup;
children = (
B0FE2F0F2154495100F3D073 /* BlurButton.swift */,
);
path = View;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -592,10 +614,12 @@
B050E14E21516AFE0090CB79 /* AppNavigator.swift in Sources */,
B0FE2F0A2154237C00F3D073 /* GenericInfoViewControllerModel.swift in Sources */,
B050E18121519B390090CB79 /* LoginViewControllerDelegate.swift in Sources */,
B0FE2F0D21543E6600F3D073 /* ImageViewerViewController.swift in Sources */,
B050E18E2151A5660090CB79 /* SettingsCellType.swift in Sources */,
B0FE2F0621541C5C00F3D073 /* GenericInfoViewController.swift in Sources */,
B0FE2F082154230500F3D073 /* GenericInfoViewControllerDelegate.swift in Sources */,
B050E1852151A3700090CB79 /* SettingsViewController.swift in Sources */,
B0FE2F102154495100F3D073 /* BlurButton.swift in Sources */,
B050E1902151A6000090CB79 /* SettingsModel.swift in Sources */,
B050E15621516D4D0090CB79 /* HomeViewController.swift in Sources */,
B050E1922151A61F0090CB79 /* SettingsSectionModel.swift in Sources */,
......
......@@ -21,12 +21,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let window = UIWindow(frame: UIScreen.main.bounds)
self.window = window
let generic = GenericInfoViewController(model: .createTestModel())
let nav = UINavigationController(rootViewController: generic)
window.rootViewController = nav
//let rootNavigator = AmivRootNavigator(window: window)
//self.rootNavigator = rootNavigator
let rootNavigator = AmivRootNavigator(window: window)
self.rootNavigator = rootNavigator
self.window?.makeKeyAndVisible()
......
//
// ImageViewerViewController.swift
// Amiv
//
// Created by Domenic Wüthrich on 20.09.18.
// Copyright © 2018 Amiv an der ETH. All rights reserved.
//
import Foundation
import UIKit
public class ImageViewerViewController: UIViewController {
// MARK: - Variables
// MARK: - View Variables
public private(set) var dismissButton: UIButton!
public private(set) var imageView: UIImageView!
public private(set) var scrollView: UIScrollView!
// MARK: - Initializers
public init(image: UIImage) {
super.init(nibName: nil, bundle: nil)
// View Creation
self.scrollView = self.createScrollView()
self.view.addSubview(self.scrollView)
self.imageView = self.createImageView(image)
self.scrollView.addSubview(imageView)
self.dismissButton = self.createDismissButton()
self.view.addSubview(self.dismissButton)
// View Constraints
self.applyImageViewConstraints()
self.applyScrollViewConstraints()
self.applyDismissButtonConstraints()
// Swipe down to dismiss viewer gesture
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(self.dismissView))
gesture.direction = .down
self.view.addGestureRecognizer(gesture)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - View Creation
private func createDismissButton() -> UIButton {
let button = BlurButton(style: .prominent)
button.setTitle("Close", for: .normal)
button.setTitleColor(.black, for: .normal)
button.setTitleColor(.darkGray, for: .highlighted)
//button.backgroundColor = .white
button.addTarget(self, action: #selector(self.dismissView), for: .touchUpInside)
button.layer.cornerRadius = 17
button.layer.masksToBounds = true
button.contentEdgeInsets = UIEdgeInsets(top: 8, left: 10, bottom: 8, right: 10)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}
private func applyDismissButtonConstraints() {
NSLayoutConstraint(item: self.dismissButton, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .topMargin, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: self.dismissButton, attribute: .leading, relatedBy: .greaterThanOrEqual, toItem: self.view, attribute: .leadingMargin, multiplier: 1, constant: 10).isActive = true
NSLayoutConstraint(item: self.dismissButton, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailingMargin, multiplier: 1, constant: -10).isActive = true
NSLayoutConstraint(item: self.dismissButton, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 34).isActive = true
}
private func createImageView(_ image: UIImage) -> UIImageView {
let view = UIImageView()
view.image = image
view.contentMode = .scaleAspectFit
view.translatesAutoresizingMaskIntoConstraints = false
return view
}
private func applyImageViewConstraints() {
NSLayoutConstraint(item: self.imageView, attribute: .top, relatedBy: .equal, toItem: self.scrollView, attribute: .top, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.imageView, attribute: .leading, relatedBy: .equal, toItem: self.scrollView, attribute: .leading, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.imageView, attribute: .trailing, relatedBy: .equal, toItem: self.scrollView, attribute: .trailing, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.imageView, attribute: .bottom, relatedBy: .equal, toItem: self.scrollView, attribute: .bottom, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.imageView, attribute: .centerX, relatedBy: .equal, toItem: self.scrollView, attribute: .centerX, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.imageView, attribute: .centerY, relatedBy: .equal, toItem: self.scrollView, attribute: .centerY, multiplier: 1, constant: 0).isActive = true
}
private func createScrollView() -> UIScrollView {
let view = UIScrollView()
view.minimumZoomScale = 1.0
view.maximumZoomScale = 5.0
view.delegate = self
view.translatesAutoresizingMaskIntoConstraints = false
return view
}
private func applyScrollViewConstraints() {
NSLayoutConstraint(item: self.scrollView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.scrollView, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.scrollView, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1, constant: 0).isActive = true
NSLayoutConstraint(item: self.scrollView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1, constant: 0).isActive = true
}
// MARK: - View Setup
// MARK: - View Interaction
@objc private func dismissView() {
debugPrint("dismissing ImageViewer")
self.dismiss(animated: false, completion: nil)
}
}
extension ImageViewerViewController: UIScrollViewDelegate {
public func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return self.imageView
}
}
......@@ -89,8 +89,13 @@ public class GenericInfoViewController: UIViewController {
let view = UIImageView()
view.image = image
view.contentMode = .scaleAspectFill
view.isUserInteractionEnabled = true
view.translatesAutoresizingMaskIntoConstraints = false
let recognizer = UITapGestureRecognizer(target: self, action: #selector(self.expandImage))
recognizer.numberOfTapsRequired = 1
view.addGestureRecognizer(recognizer)
return view
}
......@@ -192,4 +197,14 @@ public class GenericInfoViewController: UIViewController {
self.delegate?.buttonTapped()
}
@objc private func expandImage() {
debugPrint("expanding image")
guard let image = self.imageView?.image else {
return
}
let imageViewer = ImageViewerViewController(image: image)
self.present(imageViewer, animated: false, completion: nil)
}
}
//
// BlurButton.swift
// Amiv
//
// Created by Domenic Wüthrich on 20.09.18.
// Copyright © 2018 Amiv an der ETH. All rights reserved.
//
import Foundation
import UIKit
public class BlurButton: UIButton {
// MARK: - Variables
public let style: UIBlurEffect.Style
// MARK: - View Variables
public private(set) var blurBackgroundView: UIVisualEffectView!
// MARK: - Initializers
public init(style: UIBlurEffect.Style) {
self.style = style
super.init(frame: .null)
self.blurBackgroundView = self.createBackgroundLayer(style)
self.insertSubview(self.blurBackgroundView, at: 0)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - View Creation
private func createBackgroundLayer(_ style: UIBlurEffect.Style) -> UIVisualEffectView {
let blurEffect = UIBlurEffect(style: self.style)
let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.isUserInteractionEnabled = false
blurredEffectView.isExclusiveTouch = false
return blurredEffectView
}
// MARK: - Layout
public override func layoutSubviews() {
super.layoutSubviews()
self.blurBackgroundView.frame = self.bounds
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment