You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.1 KiB
102 lines
3.1 KiB
//
|
|
// AttachmentPageViewController.swift
|
|
// elpha-ios
|
|
//
|
|
// Created by Dwayne Harris on 11/1/18.
|
|
// Copyright © 2018 Elpha. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class AttachmentPageViewController: UIPageViewController {
|
|
var status: StatusMO? = nil
|
|
var controllers: [UIViewController] = []
|
|
var attachmentIndex = 0
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.presentingViewController?.tabBarController?.tabBar.isHidden = true
|
|
|
|
self.delegate = self
|
|
self.dataSource = self
|
|
|
|
if let status = status, let attachments = status.attachments {
|
|
attachments.forEach { attachment in
|
|
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AttachmentViewController") as? AttachmentViewController {
|
|
controller.attachment = attachment as? AttachmentMO
|
|
controllers.append(controller)
|
|
}
|
|
}
|
|
}
|
|
|
|
setViewControllers([controllers[attachmentIndex]], direction: .forward, animated: true, completion: nil)
|
|
}
|
|
|
|
func dismissController() {
|
|
self.presentingViewController?.tabBarController?.tabBar.isHidden = false
|
|
dismiss(animated: false)
|
|
}
|
|
|
|
override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
return .lightContent
|
|
}
|
|
|
|
override var prefersStatusBarHidden: Bool {
|
|
return true
|
|
}
|
|
|
|
override func viewDidLayoutSubviews() {
|
|
super.viewDidLayoutSubviews()
|
|
|
|
for view in view.subviews {
|
|
if view is UIScrollView {
|
|
view.frame = UIScreen.main.bounds
|
|
} else if view is UIPageControl {
|
|
view.backgroundColor = UIColor.clear
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AttachmentPageViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
|
|
func presentationCount(for pageViewController: UIPageViewController) -> Int {
|
|
return controllers.count
|
|
}
|
|
|
|
func presentationIndex(for pageViewController: UIPageViewController) -> Int {
|
|
return attachmentIndex
|
|
}
|
|
|
|
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
|
|
guard let index = controllers.index(of: viewController) else {
|
|
return nil
|
|
}
|
|
|
|
if controllers.count == 1 {
|
|
return nil
|
|
}
|
|
|
|
if index == 0 {
|
|
return controllers.last
|
|
}
|
|
|
|
return controllers[index - 1]
|
|
}
|
|
|
|
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
|
|
guard let index = controllers.index(of: viewController) else {
|
|
return nil
|
|
}
|
|
|
|
if controllers.count == 1 {
|
|
return nil
|
|
}
|
|
|
|
if index == controllers.count - 1 {
|
|
return controllers.first
|
|
}
|
|
|
|
return controllers[index + 1]
|
|
}
|
|
}
|