Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more zoom levels and more powerful zoom in on goal graph #539

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions BeeSwift/GoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Intents
import BeeKit
import OSLog

class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTableViewControllerDelegate, UITextFieldDelegate, SFSafariViewControllerDelegate {
class GoalViewController: UIViewController, DatapointTableViewControllerDelegate, UITextFieldDelegate {
let elementSpacing = 10
let sideMargin = 10
let buttonHeight = 42
Expand Down Expand Up @@ -100,7 +100,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
self.goalImageScrollView.showsHorizontalScrollIndicator = false
self.goalImageScrollView.showsVerticalScrollIndicator = false
self.goalImageScrollView.minimumZoomScale = 1.0
self.goalImageScrollView.maximumZoomScale = 3.0
self.goalImageScrollView.maximumZoomScale = 7.0
self.goalImageScrollView.delegate = self
self.goalImageScrollView.snp.makeConstraints { (make) -> Void in
make.centerX.equalTo(self.view)
Expand Down Expand Up @@ -346,7 +346,10 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl
}

@objc func goalImageTapped() {
self.goalImageScrollView.setZoomScale(self.goalImageScrollView.zoomScale == 1.0 ? 2.0 : 1.0, animated: true)
let possibleNextStepUp = self.goalImageScrollView.zoomScale + 2.0
let nextZoomLevel = possibleNextStepUp <= self.goalImageScrollView.maximumZoomScale ? possibleNextStepUp : self.goalImageScrollView.minimumZoomScale

self.goalImageScrollView.setZoomScale(nextZoomLevel, animated: true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable for iPhone. I'm less sure it makes sense for iPad though? Perhaps the max zoom level should be a function of the screen size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still found it quite OK to double tap to zoom on the iPad. The bigger issue for me was that the graph image being used quickly becomes blurry since we are using the lower resolution png rather than the svg. The user can still pinch-to-zoom and can do so at the previous level as well as now also at other levels.

}

func datapointTableViewController(_ datapointTableViewController: DatapointTableViewController, didSelectDatapoint datapoint: BeeDataPoint) {
Expand Down Expand Up @@ -484,10 +487,6 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl

self.refreshCountdown()
}

func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return self.goalImageView
}

private static func makeInitialDateStepperValue(date: Date = Date(), for goal: Goal) -> Double {
let daystampAccountingForTheGoalsDeadline = Daystamp(fromDate: date,
Expand All @@ -497,15 +496,20 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl

return Double(daystampAssumingMidnightDeadline.distance(to: daystampAccountingForTheGoalsDeadline))
}
}

// MARK: - SFSafariViewControllerDelegate
extension GoalViewController: UIScrollViewDelegate {
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return self.goalImageView
}
}

extension GoalViewController: SFSafariViewControllerDelegate {
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller.dismiss(animated: true, completion: nil)
}
}


private extension DateFormatter {
private static let urtextDateFormatter: DateFormatter = {
let formatter = DateFormatter()
Expand Down
Loading