From 8c3afb0a96d415a181cbb67dae25db4696ede008 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 30 Jun 2016 11:59:47 -0400 Subject: [PATCH 1/4] Basic setup --- Kiwix-iOS/Controller/MainVC.swift | 47 ++++++-- ....swift => TableOfContentsController.swift} | 34 ++++-- Kiwix-iOS/Info.plist | 14 ++- Kiwix-iOS/Storyboard/Main.storyboard | 107 +++++++++++++----- Kiwix-iOS/Storyboard/Search.storyboard | 8 +- Kiwix.xcodeproj/project.pbxproj | 8 +- 6 files changed, 163 insertions(+), 55 deletions(-) rename Kiwix-iOS/Controller/{TableOfContentController.swift => TableOfContentsController.swift} (64%) diff --git a/Kiwix-iOS/Controller/MainVC.swift b/Kiwix-iOS/Controller/MainVC.swift index 5dd00023..a9663e30 100644 --- a/Kiwix-iOS/Controller/MainVC.swift +++ b/Kiwix-iOS/Controller/MainVC.swift @@ -9,9 +9,12 @@ import UIKit class MainVC: UIViewController { - + @IBOutlet weak var webView: UIWebView! - var tableOfContentController: TableOfContentController? + @IBOutlet weak var tocControllerBottomSpacing: NSLayoutConstraint! + @IBOutlet weak var tocControllerHeight: NSLayoutConstraint! + + var tableOfContentsController: TableOfContentsController? var bookmarkController: UIViewController? var libraryController: UIViewController? var settingController: UIViewController? @@ -40,6 +43,8 @@ class MainVC: UIViewController { NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewZoomScale", options: .New, context: context) configureButtonColor() showGetStartedAlert() + + tocControllerBottomSpacing.constant = -tocControllerHeight.constant } deinit { @@ -54,7 +59,7 @@ class MainVC: UIViewController { override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() - tableOfContentController = nil + tableOfContentsController = nil bookmarkController = nil libraryController = nil settingController = nil @@ -68,6 +73,14 @@ class MainVC: UIViewController { } } + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + if segue.identifier == "EmbeddedTOCController" { + guard let destinationViewController = segue.destinationViewController as? TableOfContentsController else {return} + tableOfContentsController = destinationViewController + tableOfContentsController?.delegate = self + } + } + // MARK: - First Time Launch Alert func showGetStartedAlert() { @@ -100,7 +113,6 @@ class MainVC: UIViewController { case .Unspecified: break } -// configureWebViewInsets() } func configureButtonColor() { @@ -225,14 +237,7 @@ class MainVC: UIViewController { } func showTableOfContentButtonTapped(sender: UIBarButtonItem) { - guard let controller = tableOfContentController ?? UIStoryboard.main.initViewController(TableOfContentController.self) else {return} - controller.modalPresentationStyle = .Popover - controller.popoverPresentationController?.barButtonItem = sender - controller.popoverPresentationController?.permittedArrowDirections = [.Up, .Down] - controller.popoverPresentationController?.delegate = self - controller.headings = getTableOfContents(webView) - controller.delegate = self - presentViewController(controller, animated: true, completion: nil) + toggleTableOfContents() } func showLibraryButtonTapped() { @@ -253,4 +258,22 @@ class MainVC: UIViewController { hideSearch() navigationItem.setRightBarButtonItem(nil, animated: true) } + + // MARK: - TOC + + func toggleTableOfContents() { + let tocIsShowing = tocControllerBottomSpacing.constant == 0 + let option: UIViewAnimationOptions = tocIsShowing ? .CurveEaseIn : .CurveEaseOut + + if (!tocIsShowing) { + tableOfContentsController?.headings = getTableOfContents(webView) + } + + view.layoutIfNeeded() + tocControllerBottomSpacing.constant = tocIsShowing ? -tocControllerHeight.constant : 0.0 + + UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.0, options: option, animations: { + self.view.layoutIfNeeded() + }, completion: nil) + } } diff --git a/Kiwix-iOS/Controller/TableOfContentController.swift b/Kiwix-iOS/Controller/TableOfContentsController.swift similarity index 64% rename from Kiwix-iOS/Controller/TableOfContentController.swift rename to Kiwix-iOS/Controller/TableOfContentsController.swift index 7afce746..0358f507 100644 --- a/Kiwix-iOS/Controller/TableOfContentController.swift +++ b/Kiwix-iOS/Controller/TableOfContentsController.swift @@ -1,5 +1,5 @@ // -// TableOfContentController.swift +// TableOfContentsController.swift // Kiwix // // Created by Chris Li on 6/26/16. @@ -9,10 +9,12 @@ import UIKit import DZNEmptyDataSet -class TableOfContentController: UITableViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { +class TableOfContentsController: UIViewController, UITableViewDelegate, UITableViewDataSource ,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate { + @IBOutlet weak var tableView: UITableView! weak var delegate: TableOfContentsDelegate? private var headinglevelMin = 0 + var headings = [HTMLHeading]() { didSet { configurePreferredContentSize() @@ -23,6 +25,8 @@ class TableOfContentController: UITableViewController, DZNEmptyDataSetSource, DZ override func viewDidLoad() { super.viewDidLoad() + tableView.delegate = self + tableView.dataSource = self tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self tableView.tableFooterView = UIView() @@ -33,18 +37,34 @@ class TableOfContentController: UITableViewController, DZNEmptyDataSetSource, DZ let width = traitCollection.horizontalSizeClass == .Regular ? 300 : (UIScreen.mainScreen().bounds.width) preferredContentSize = CGSizeMake(width, count == 0 ? 350 : min(CGFloat(count) * 44.0, UIScreen.mainScreen().bounds.height * 0.8)) } + + override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { + guard previousTraitCollection != traitCollection else {return} + let bottomInset: CGFloat = { + switch (traitCollection.horizontalSizeClass, traitCollection.verticalSizeClass) { + case (.Compact, .Regular): + return 44.0 + case (.Compact, .Compact): + return 32.0 + default: + return 0.0 + } + }() + tableView.contentInset = UIEdgeInsetsMake(0, 0, bottomInset, 0) + tableView.scrollIndicatorInsets = tableView.contentInset + } // MARK: - Table view data source - override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return headings.count } - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) cell.textLabel?.text = headings[indexPath.row].textContent cell.indentationLevel = (headings[indexPath.row].level - headinglevelMin) * 2 @@ -53,7 +73,7 @@ class TableOfContentController: UITableViewController, DZNEmptyDataSetSource, DZ // MARK: - Table view delegate - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { delegate?.scrollTo(headings[indexPath.row]) } @@ -71,7 +91,7 @@ class TableOfContentController: UITableViewController, DZNEmptyDataSetSource, DZ } func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat { - return 0 + return -10.0 } func spaceHeightForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat { diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index fa019297..24bf445f 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -36,7 +36,7 @@ CFBundleSignature ???? CFBundleVersion - 924 + 1013 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS @@ -44,7 +44,17 @@ NSAppTransportSecurity NSAllowsArbitraryLoads - + + NSExceptionDomains + + kiwix.org + + NSExceptionAllowsInsecureHTTPLoads + + NSIncludesSubdomains + + + UIFileSharingEnabled diff --git a/Kiwix-iOS/Storyboard/Main.storyboard b/Kiwix-iOS/Storyboard/Main.storyboard index e5ef55a9..2a9f76b4 100644 --- a/Kiwix-iOS/Storyboard/Main.storyboard +++ b/Kiwix-iOS/Storyboard/Main.storyboard @@ -204,35 +204,52 @@ - + - - + + - - - + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -322,7 +339,7 @@ - + @@ -340,6 +357,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -352,9 +402,12 @@ + + + @@ -364,6 +417,8 @@ + + diff --git a/Kiwix-iOS/Storyboard/Search.storyboard b/Kiwix-iOS/Storyboard/Search.storyboard index 0d276a78..8a6a20ca 100644 --- a/Kiwix-iOS/Storyboard/Search.storyboard +++ b/Kiwix-iOS/Storyboard/Search.storyboard @@ -350,9 +350,9 @@ - - + + @@ -908,11 +908,11 @@ - - + + diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj index b66a496b..5be9049c 100644 --- a/Kiwix.xcodeproj/project.pbxproj +++ b/Kiwix.xcodeproj/project.pbxproj @@ -259,7 +259,7 @@ 97BA32A51CEBC36300339A47 /* RootWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97BA32A31CEBC29500339A47 /* RootWindowController.swift */; }; 97D452BC1D16FF010033666F /* RecentSearchCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D452BB1D16FF010033666F /* RecentSearchCVC.swift */; }; 97D452BE1D1723FF0033666F /* CollectionViewCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D452BD1D1723FF0033666F /* CollectionViewCells.swift */; }; - 97D55EF61D2075180081B523 /* TableOfContentController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D55EF51D2075180081B523 /* TableOfContentController.swift */; }; + 97D55EF61D2075180081B523 /* TableOfContentsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D55EF51D2075180081B523 /* TableOfContentsController.swift */; }; 97DF23551CE807A1003E1E5A /* GlobalOperationQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97DF23541CE807A1003E1E5A /* GlobalOperationQueue.swift */; }; 97E609F11D103DED00EBCB9D /* NotificationCenter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97E609F01D103DED00EBCB9D /* NotificationCenter.framework */; }; 97E609F41D103DED00EBCB9D /* TodayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E609F31D103DED00EBCB9D /* TodayViewController.swift */; }; @@ -537,7 +537,7 @@ 97D452BD1D1723FF0033666F /* CollectionViewCells.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCells.swift; sourceTree = ""; }; 97D452C01D1871E70033666F /* SearchLocalBooksCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SearchLocalBooksCVC.swift; path = "Kiwix-iOS/Controller/Search/SearchLocalBooksCVC.swift"; sourceTree = SOURCE_ROOT; }; 97D452C11D1871E70033666F /* SearchTabController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SearchTabController.swift; path = "Kiwix-iOS/Controller/Search/SearchTabController.swift"; sourceTree = SOURCE_ROOT; }; - 97D55EF51D2075180081B523 /* TableOfContentController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TableOfContentController.swift; path = "Kiwix-iOS/Controller/TableOfContentController.swift"; sourceTree = SOURCE_ROOT; }; + 97D55EF51D2075180081B523 /* TableOfContentsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TableOfContentsController.swift; path = "Kiwix-iOS/Controller/TableOfContentsController.swift"; sourceTree = SOURCE_ROOT; }; 97DF23541CE807A1003E1E5A /* GlobalOperationQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalOperationQueue.swift; sourceTree = ""; }; 97E609EF1D103DED00EBCB9D /* Kiwix-iOSWidget.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Kiwix-iOSWidget.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 97E609F01D103DED00EBCB9D /* NotificationCenter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NotificationCenter.framework; path = System/Library/Frameworks/NotificationCenter.framework; sourceTree = SDKROOT; }; @@ -1028,7 +1028,7 @@ 972B007D1C35DBAB00B5FDC5 /* MainVC */, 97E108221C5D5A0D00E27FD3 /* Search */, 9771DC4B1C37278E009ECFF0 /* Setting */, - 97D55EF51D2075180081B523 /* TableOfContentController.swift */, + 97D55EF51D2075180081B523 /* TableOfContentsController.swift */, 971A10691D022E15007FC62C /* BookmarkHUDVC.swift */, ); name = Controllers; @@ -1890,7 +1890,7 @@ 979CB6B71D05C520005E1BA1 /* LocationOperation.swift in Sources */, 971A102F1D022AD5007FC62C /* Logo.swift in Sources */, 979CB6451D05C44F005E1BA1 /* Capability.swift in Sources */, - 97D55EF61D2075180081B523 /* TableOfContentController.swift in Sources */, + 97D55EF61D2075180081B523 /* TableOfContentsController.swift in Sources */, 971A104B1D022CBE007FC62C /* SearchBooksVC.swift in Sources */, 977998771C1E0B7900B1DD5E /* Article+CoreDataProperties.swift in Sources */, 971187301CEB50FC00B9909D /* ZimReader.mm in Sources */, From b548b5c99f32bc774b4bdf093fcdba2f78bb62c9 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 30 Jun 2016 14:56:55 -0400 Subject: [PATCH 2/4] wCompact finished wCompact finished --- Kiwix-iOS/Controller/MainVC.swift | 72 +++++++++++++------ .../TableOfContentsController.swift | 18 +---- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Main.storyboard | 49 ++++++++++--- 4 files changed, 91 insertions(+), 50 deletions(-) diff --git a/Kiwix-iOS/Controller/MainVC.swift b/Kiwix-iOS/Controller/MainVC.swift index a9663e30..5b1d7f52 100644 --- a/Kiwix-iOS/Controller/MainVC.swift +++ b/Kiwix-iOS/Controller/MainVC.swift @@ -11,8 +11,10 @@ import UIKit class MainVC: UIViewController { @IBOutlet weak var webView: UIWebView! - @IBOutlet weak var tocControllerBottomSpacing: NSLayoutConstraint! - @IBOutlet weak var tocControllerHeight: NSLayoutConstraint! + @IBOutlet weak var dimView: UIView! + @IBOutlet weak var visiualEffectView: UIVisualEffectView! + @IBOutlet weak var tocTopToSuperViewBottomSpacing: NSLayoutConstraint! + @IBOutlet weak var tocHeightConstraint: NSLayoutConstraint! var tableOfContentsController: TableOfContentsController? var bookmarkController: UIViewController? @@ -28,6 +30,8 @@ class MainVC: UIViewController { let navBarMinHeight: CGFloat = 10.0 var previousScrollViewYOffset: CGFloat = 0.0 + var isShowingTableOfContents = false + // MARK: - Override override func viewDidLoad() { @@ -43,8 +47,6 @@ class MainVC: UIViewController { NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewZoomScale", options: .New, context: context) configureButtonColor() showGetStartedAlert() - - tocControllerBottomSpacing.constant = -tocControllerHeight.constant } deinit { @@ -204,6 +206,9 @@ class MainVC: UIViewController { if UIDevice.currentDevice().userInterfaceIdiom == .Pad && traitCollection.horizontalSizeClass == .Compact { navigationItem.setRightBarButtonItem(cancelButton, animated: true) } + if isShowingTableOfContents { + animateOutTableOfContentsController() + } } func hideSearch() { @@ -215,6 +220,41 @@ class MainVC: UIViewController { navigationItem.setRightBarButtonItem(nil, animated: true) } } + + // MARK: - TOC + + func animateInTableOfContentsController() { + dimView.hidden = false + dimView.alpha = 0.0 + view.layoutIfNeeded() + tableOfContentsController?.headings = getTableOfContents(webView) + let tocHeight: CGFloat = { + guard let controller = tableOfContentsController else {return floor(view.frame.height * 0.4)} + let preferredHeight = controller.preferredContentSize.height + guard controller.headings.count != 0 else {return floor(view.frame.height * 0.4)} + return min(preferredHeight + 44, floor(view.frame.height * 0.65)) + }() + tocHeightConstraint.constant = tocHeight + tocTopToSuperViewBottomSpacing.constant = tocHeight + UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { + self.view.layoutIfNeeded() + self.dimView.alpha = 0.5 + }) { (completed) in + self.isShowingTableOfContents = true + } + } + + func animateOutTableOfContentsController() { + view.layoutIfNeeded() + tocTopToSuperViewBottomSpacing.constant = 0.0 + UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseIn, animations: { + self.view.layoutIfNeeded() + self.dimView.alpha = 0.0 + }) { (completed) in + self.dimView.hidden = true + self.isShowingTableOfContents = false + } + } // MARK: - Buttons @@ -237,7 +277,11 @@ class MainVC: UIViewController { } func showTableOfContentButtonTapped(sender: UIBarButtonItem) { - toggleTableOfContents() + if isShowingTableOfContents { + animateOutTableOfContentsController() + } else { + animateInTableOfContentsController() + } } func showLibraryButtonTapped() { @@ -259,21 +303,7 @@ class MainVC: UIViewController { navigationItem.setRightBarButtonItem(nil, animated: true) } - // MARK: - TOC - - func toggleTableOfContents() { - let tocIsShowing = tocControllerBottomSpacing.constant == 0 - let option: UIViewAnimationOptions = tocIsShowing ? .CurveEaseIn : .CurveEaseOut - - if (!tocIsShowing) { - tableOfContentsController?.headings = getTableOfContents(webView) - } - - view.layoutIfNeeded() - tocControllerBottomSpacing.constant = tocIsShowing ? -tocControllerHeight.constant : 0.0 - - UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.0, options: option, animations: { - self.view.layoutIfNeeded() - }, completion: nil) + @IBAction func dimViewTapGestureRecognizer(sender: UITapGestureRecognizer) { + animateOutTableOfContentsController() } } diff --git a/Kiwix-iOS/Controller/TableOfContentsController.swift b/Kiwix-iOS/Controller/TableOfContentsController.swift index 0358f507..abbd3635 100644 --- a/Kiwix-iOS/Controller/TableOfContentsController.swift +++ b/Kiwix-iOS/Controller/TableOfContentsController.swift @@ -37,22 +37,6 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV let width = traitCollection.horizontalSizeClass == .Regular ? 300 : (UIScreen.mainScreen().bounds.width) preferredContentSize = CGSizeMake(width, count == 0 ? 350 : min(CGFloat(count) * 44.0, UIScreen.mainScreen().bounds.height * 0.8)) } - - override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { - guard previousTraitCollection != traitCollection else {return} - let bottomInset: CGFloat = { - switch (traitCollection.horizontalSizeClass, traitCollection.verticalSizeClass) { - case (.Compact, .Regular): - return 44.0 - case (.Compact, .Compact): - return 32.0 - default: - return 0.0 - } - }() - tableView.contentInset = UIEdgeInsetsMake(0, 0, bottomInset, 0) - tableView.scrollIndicatorInsets = tableView.contentInset - } // MARK: - Table view data source @@ -91,7 +75,7 @@ class TableOfContentsController: UIViewController, UITableViewDelegate, UITableV } func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat { - return -10.0 + return 0.0 } func spaceHeightForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat { diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 24bf445f..84a0c799 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -36,7 +36,7 @@ CFBundleSignature ???? CFBundleVersion - 1013 + 1207 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Main.storyboard b/Kiwix-iOS/Storyboard/Main.storyboard index 2a9f76b4..1f999ffa 100644 --- a/Kiwix-iOS/Storyboard/Main.storyboard +++ b/Kiwix-iOS/Storyboard/Main.storyboard @@ -215,11 +215,11 @@ - + - + @@ -358,15 +358,15 @@ - + - + - + - + @@ -380,16 +380,30 @@ + - + + + + + + - + + @@ -402,9 +416,14 @@ + + + + + - + @@ -412,17 +431,25 @@ + - - + + + + + + + + + From d68f474fe5990b1b98e5330b6774e1c1116a9ea8 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 30 Jun 2016 15:24:57 -0400 Subject: [PATCH 3/4] hCompact finished (revise) --- Kiwix-iOS/Controller/MainVC.swift | 22 ++++++++++++++-------- Kiwix-iOS/Info.plist | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Kiwix-iOS/Controller/MainVC.swift b/Kiwix-iOS/Controller/MainVC.swift index 5b1d7f52..a053d423 100644 --- a/Kiwix-iOS/Controller/MainVC.swift +++ b/Kiwix-iOS/Controller/MainVC.swift @@ -72,6 +72,7 @@ class MainVC: UIViewController { super.traitCollectionDidChange(previousTraitCollection) if previousTraitCollection?.horizontalSizeClass != traitCollection.horizontalSizeClass { configureUIElements(traitCollection.horizontalSizeClass) + if let _ = previousTraitCollection {configureTOCViewConstraints()} } } @@ -228,14 +229,7 @@ class MainVC: UIViewController { dimView.alpha = 0.0 view.layoutIfNeeded() tableOfContentsController?.headings = getTableOfContents(webView) - let tocHeight: CGFloat = { - guard let controller = tableOfContentsController else {return floor(view.frame.height * 0.4)} - let preferredHeight = controller.preferredContentSize.height - guard controller.headings.count != 0 else {return floor(view.frame.height * 0.4)} - return min(preferredHeight + 44, floor(view.frame.height * 0.65)) - }() - tocHeightConstraint.constant = tocHeight - tocTopToSuperViewBottomSpacing.constant = tocHeight + configureTOCViewConstraints() UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.0, options: .CurveEaseOut, animations: { self.view.layoutIfNeeded() self.dimView.alpha = 0.5 @@ -255,6 +249,18 @@ class MainVC: UIViewController { self.isShowingTableOfContents = false } } + + func configureTOCViewConstraints() { + let tocHeight: CGFloat = { + guard let controller = tableOfContentsController else {return floor(view.frame.height * 0.4)} + let preferredHeight = controller.preferredContentSize.height + guard controller.headings.count != 0 else {return floor(view.frame.height * 0.4)} + let toolBarHeight: CGFloat = traitCollection.horizontalSizeClass == .Regular ? 0.0 : (traitCollection.verticalSizeClass == .Compact ? 32.0 : 44.0) + return min(preferredHeight + toolBarHeight, floor(view.frame.height * 0.65)) + }() + tocHeightConstraint.constant = tocHeight + tocTopToSuperViewBottomSpacing.constant = tocHeight + } // MARK: - Buttons diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 84a0c799..5ae4b52b 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -36,7 +36,7 @@ CFBundleSignature ???? CFBundleVersion - 1207 + 1218 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS From faf77b2410fc6a74f79019e0aea962dc5f9c1578 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 1 Jul 2016 21:17:55 -0400 Subject: [PATCH 4/4] finished --- Kiwix-iOS/Controller/MainVC.swift | 42 ++-- Kiwix-iOS/Controller/MainVCDelegates.swift | 7 + Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Main.storyboard | 229 +++++++++++++++++---- 4 files changed, 222 insertions(+), 58 deletions(-) diff --git a/Kiwix-iOS/Controller/MainVC.swift b/Kiwix-iOS/Controller/MainVC.swift index a053d423..185d11c1 100644 --- a/Kiwix-iOS/Controller/MainVC.swift +++ b/Kiwix-iOS/Controller/MainVC.swift @@ -12,9 +12,10 @@ class MainVC: UIViewController { @IBOutlet weak var webView: UIWebView! @IBOutlet weak var dimView: UIView! - @IBOutlet weak var visiualEffectView: UIVisualEffectView! + @IBOutlet weak var tocVisiualEffectView: UIVisualEffectView! @IBOutlet weak var tocTopToSuperViewBottomSpacing: NSLayoutConstraint! @IBOutlet weak var tocHeightConstraint: NSLayoutConstraint! + @IBOutlet weak var tocLeadSpacing: NSLayoutConstraint! var tableOfContentsController: TableOfContentsController? var bookmarkController: UIViewController? @@ -72,8 +73,8 @@ class MainVC: UIViewController { super.traitCollectionDidChange(previousTraitCollection) if previousTraitCollection?.horizontalSizeClass != traitCollection.horizontalSizeClass { configureUIElements(traitCollection.horizontalSizeClass) - if let _ = previousTraitCollection {configureTOCViewConstraints()} } + configureTOCViewConstraints() } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { @@ -207,7 +208,7 @@ class MainVC: UIViewController { if UIDevice.currentDevice().userInterfaceIdiom == .Pad && traitCollection.horizontalSizeClass == .Compact { navigationItem.setRightBarButtonItem(cancelButton, animated: true) } - if isShowingTableOfContents { + if isShowingTableOfContents && traitCollection.horizontalSizeClass == .Compact { animateOutTableOfContentsController() } } @@ -225,6 +226,8 @@ class MainVC: UIViewController { // MARK: - TOC func animateInTableOfContentsController() { + isShowingTableOfContents = true + tocVisiualEffectView.hidden = false dimView.hidden = false dimView.alpha = 0.0 view.layoutIfNeeded() @@ -234,32 +237,41 @@ class MainVC: UIViewController { self.view.layoutIfNeeded() self.dimView.alpha = 0.5 }) { (completed) in - self.isShowingTableOfContents = true + } } func animateOutTableOfContentsController() { + isShowingTableOfContents = false view.layoutIfNeeded() - tocTopToSuperViewBottomSpacing.constant = 0.0 + configureTOCViewConstraints() UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveEaseIn, animations: { self.view.layoutIfNeeded() self.dimView.alpha = 0.0 }) { (completed) in self.dimView.hidden = true - self.isShowingTableOfContents = false + self.tocVisiualEffectView.hidden = true } } func configureTOCViewConstraints() { - let tocHeight: CGFloat = { - guard let controller = tableOfContentsController else {return floor(view.frame.height * 0.4)} - let preferredHeight = controller.preferredContentSize.height - guard controller.headings.count != 0 else {return floor(view.frame.height * 0.4)} - let toolBarHeight: CGFloat = traitCollection.horizontalSizeClass == .Regular ? 0.0 : (traitCollection.verticalSizeClass == .Compact ? 32.0 : 44.0) - return min(preferredHeight + toolBarHeight, floor(view.frame.height * 0.65)) - }() - tocHeightConstraint.constant = tocHeight - tocTopToSuperViewBottomSpacing.constant = tocHeight + switch traitCollection.horizontalSizeClass { + case .Compact: + let tocHeight: CGFloat = { + guard let controller = tableOfContentsController else {return floor(view.frame.height * 0.4)} + let tocContentHeight = controller.tableView.contentSize.height + guard controller.headings.count != 0 else {return floor(view.frame.height * 0.4)} + let toolBarHeight: CGFloat = traitCollection.horizontalSizeClass == .Regular ? 0.0 : (traitCollection.verticalSizeClass == .Compact ? 32.0 : 44.0) + return min(tocContentHeight + toolBarHeight, floor(view.frame.height * 0.65)) + }() + tocHeightConstraint.constant = tocHeight + tocTopToSuperViewBottomSpacing.constant = isShowingTableOfContents ? tocHeight : 0.0 + case .Regular: + tocLeadSpacing.constant = isShowingTableOfContents ? 0.0 : 270 + break + default: + break + } } // MARK: - Buttons diff --git a/Kiwix-iOS/Controller/MainVCDelegates.swift b/Kiwix-iOS/Controller/MainVCDelegates.swift index 4c106ac2..e581e256 100644 --- a/Kiwix-iOS/Controller/MainVCDelegates.swift +++ b/Kiwix-iOS/Controller/MainVCDelegates.swift @@ -37,6 +37,9 @@ extension MainVC: LPTBarButtonItemDelegate, TableOfContentsDelegate, UISearchBar func scrollTo(heading: HTMLHeading) { webView.stringByEvaluatingJavaScriptFromString(heading.scrollToJavaScript) + if traitCollection.horizontalSizeClass == .Compact { + animateOutTableOfContentsController() + } } // MARK: - UISearchBarDelegate @@ -94,6 +97,10 @@ extension MainVC: LPTBarButtonItemDelegate, TableOfContentsDelegate, UISearchBar adjustFontSizeIfNeeded() configureNavigationButtonTint() configureBookmarkButton() + + if traitCollection.horizontalSizeClass == .Regular && isShowingTableOfContents { + tableOfContentsController?.headings = getTableOfContents(webView) + } } func injectTableWrappingJavaScriptIfNeeded() { diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index 5ae4b52b..2d6ae4c1 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -36,7 +36,7 @@ CFBundleSignature ???? CFBundleVersion - 1218 + 1366 ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/Kiwix-iOS/Storyboard/Main.storyboard b/Kiwix-iOS/Storyboard/Main.storyboard index 1f999ffa..de0a8edf 100644 --- a/Kiwix-iOS/Storyboard/Main.storyboard +++ b/Kiwix-iOS/Storyboard/Main.storyboard @@ -209,7 +209,7 @@ - + @@ -222,27 +222,102 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -357,7 +432,7 @@ - + - - - - + + + + + @@ -451,7 +596,7 @@ - +