Skip to content
Open

Jw #13

Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Version](https://img.shields.io/cocoapods/v/THScrollView-minimap.svg?style=flat)](http://cocoapods.org/pods)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](https://github.com/younatics/YNDropDownMenu/blob/master/LICENSE)
[![Code Coverage](https://codecov.io/gh/TileImageTeamiOS/THScrollView-minimap/branch/master/graphs/badge.svg)](https://github.com/TileImageTeamiOS/THScrollView-mminimap)
[![Build Status](https://travis-ci.org/TileImageTeamiOS/THScrollView-minimap.svg?branch=master)](https://travis-ci.org/TileImageTeamiOS/THScrollView-minimap)
[![Build Status](https://travis-ci.org/TileImageTeamiOS/THScrollViewMinimap.svg?branch=master)](https://travis-ci.org/TileImageTeamiOS/THScrollView-minimap)
[![Platform](https://img.shields.io/cocoapods/p/YNDropDownMenu.svg?style=flat)](http://cocoapods.org/pods)
[![Swift 4.0](https://img.shields.io/badge/Swift-4.0-%23FB613C.svg)](https://developer.apple.com/swift/)

Expand Down
File renamed without changes.
8 changes: 0 additions & 8 deletions THScrollViewMinimap.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
4E85FD64203FEEBF0051C192 /* THScrollViewMinimapTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E85FD63203FEEBF0051C192 /* THScrollViewMinimapTests.swift */; };
4EBE66B0200B18060091FA38 /* smallBench.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4EBE66AF200B18060091FA38 /* smallBench.jpg */; };
4EBE66B2200B183C0091FA38 /* bench.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 4EBE66B1200B183C0091FA38 /* bench.jpg */; };
7EF0774D2004BB3F0069E462 /* MyMinimapDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EF0774C2004BB3F0069E462 /* MyMinimapDataSource.swift */; };
7EF0774F2004BB740069E462 /* THMinimapDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EF0774E2004BB740069E462 /* THMinimapDataSource.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -44,8 +42,6 @@
4E85FD65203FEEBF0051C192 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4EBE66AF200B18060091FA38 /* smallBench.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = smallBench.jpg; sourceTree = "<group>"; };
4EBE66B1200B183C0091FA38 /* bench.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = bench.jpg; sourceTree = "<group>"; };
7EF0774C2004BB3F0069E462 /* MyMinimapDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyMinimapDataSource.swift; sourceTree = "<group>"; };
7EF0774E2004BB740069E462 /* THMinimapDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = THMinimapDataSource.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -70,7 +66,6 @@
isa = PBXGroup;
children = (
4E78A4651FF7585500F8CB54 /* THMinimapView.swift */,
7EF0774E2004BB740069E462 /* THMinimapDataSource.swift */,
);
path = THMinimap;
sourceTree = "<group>";
Expand Down Expand Up @@ -100,7 +95,6 @@
4EBE66AF200B18060091FA38 /* smallBench.jpg */,
4E78A44E1FF7406B00F8CB54 /* AppDelegate.swift */,
4E78A4501FF7406B00F8CB54 /* ViewController.swift */,
7EF0774C2004BB3F0069E462 /* MyMinimapDataSource.swift */,
4E78A4521FF7406B00F8CB54 /* Main.storyboard */,
4E78A4581FF7406B00F8CB54 /* Assets.xcassets */,
4E78A45A1FF7406B00F8CB54 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -241,8 +235,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7EF0774D2004BB3F0069E462 /* MyMinimapDataSource.swift in Sources */,
7EF0774F2004BB740069E462 /* THMinimapDataSource.swift in Sources */,
4E78A4511FF7406B00F8CB54 /* ViewController.swift in Sources */,
4E78A4661FF7585500F8CB54 /* THMinimapView.swift in Sources */,
4E78A44F1FF7406B00F8CB54 /* AppDelegate.swift in Sources */,
Expand Down
36 changes: 5 additions & 31 deletions THScrollViewMinimap/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,25 @@
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="THScrollView_minimap" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="THScrollViewMinimap" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="YNR-Fx-Gc8">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="bench" translatesAutoresizingMaskIntoConstraints="NO" id="ldI-Kz-eGD">
<rect key="frame" x="0.0" y="0.0" width="5214" height="7300"/>
</imageView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="ldI-Kz-eGD" secondAttribute="bottom" id="Dle-rr-2st"/>
<constraint firstItem="ldI-Kz-eGD" firstAttribute="leading" secondItem="YNR-Fx-Gc8" secondAttribute="leading" id="Kwe-ru-KAw"/>
<constraint firstAttribute="trailing" secondItem="ldI-Kz-eGD" secondAttribute="trailing" id="Qei-1e-hWx"/>
<constraint firstItem="ldI-Kz-eGD" firstAttribute="top" secondItem="YNR-Fx-Gc8" secondAttribute="top" id="mRZ-Zo-T7i"/>
</constraints>
</scrollView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="bz8-JG-15v" customClass="THMinimapView" customModule="THScrollView_minimap" customModuleProvider="target">
<rect key="frame" x="254" y="546" width="100" height="100"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="100" id="5CR-g6-gxW"/>
<constraint firstAttribute="width" constant="100" id="EYg-Yo-j1b"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="YNR-Fx-Gc8" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="3pw-57-cqm"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="bz8-JG-15v" secondAttribute="bottom" constant="21" id="46O-jk-Eiw"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="bz8-JG-15v" secondAttribute="trailing" constant="21" id="8Sf-7U-Xuh"/>
<constraint firstAttribute="trailing" secondItem="YNR-Fx-Gc8" secondAttribute="trailing" id="FR3-Hs-JEb"/>
<constraint firstItem="YNR-Fx-Gc8" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="V0Q-Tf-hdt"/>
<constraint firstItem="YNR-Fx-Gc8" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="beK-wt-93e"/>
<constraint firstItem="YNR-Fx-Gc8" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="INF-gY-zml"/>
<constraint firstItem="YNR-Fx-Gc8" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="W9N-ls-Esr"/>
<constraint firstItem="YNR-Fx-Gc8" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="aFV-Le-lYr"/>
<constraint firstItem="YNR-Fx-Gc8" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="o3i-B6-ais"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="imageView" destination="ldI-Kz-eGD" id="L9S-cb-4Sy"/>
<outlet property="minimapView" destination="bz8-JG-15v" id="YlM-ap-FxT"/>
<outlet property="scrollView" destination="YNR-Fx-Gc8" id="Xho-15-A9Z"/>
</connections>
</viewController>
Expand All @@ -63,7 +40,4 @@
<point key="canvasLocation" x="136.80000000000001" y="133.5832083958021"/>
</scene>
</scenes>
<resources>
<image name="bench" width="5214" height="7300"/>
</resources>
</document>
28 changes: 0 additions & 28 deletions THScrollViewMinimap/MyMinimapDataSource.swift

This file was deleted.

97 changes: 0 additions & 97 deletions THScrollViewMinimap/THMinimap/THMinimapDataSource.swift

This file was deleted.

108 changes: 77 additions & 31 deletions THScrollViewMinimap/THMinimap/THMinimapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,91 @@
//

import UIKit
import AVFoundation

open class THMinimapView: UIView {
public var focusedBorderWidth: CGFloat = 2.0
public var focusedBorderColor: CGColor = UIColor.yellow.cgColor
private var focusedBoxView: UIView = UIView()
private var scrollView: UIScrollView = UIScrollView()
private var minimapImageView: UIImageView = UIImageView()
private var scrollImageView: UIImageView = UIImageView()
private var downSizeRatio: CGFloat = 4.0
private var image = UIImage()
private var minimapImage: UIImage?
convenience init(scrollView: UIScrollView, downSizeRatio: CGFloat, image: UIImage) {
self.init(frame: CGRect.zero)
setUp(scrollView: scrollView, downSizeRatio: downSizeRatio, image: image, minimapImage: nil)
}
convenience init(scrollView: UIScrollView, downSizeRatio: CGFloat, image: UIImage, minimapImage: UIImage) {
self.init(frame: CGRect.zero)
setUp(scrollView: scrollView, downSizeRatio: downSizeRatio, image: image, minimapImage: minimapImage)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is THMinimapViewcan still be used from storyboard with setUp(scrollView:downSizeRatio:image:minimapImage) ?
Call default setUp()function, or you should handle required property from another function.(not from init)
For example,

let minimapView = THMinimapView()
minimapView.setup(scrollView: scrollView, downSizeRatio: downSizeRatio, image: image, minimapImage: minimapImage)

private func setUp(scrollView: UIScrollView, downSizeRatio: CGFloat, image: UIImage, minimapImage: UIImage?) {
let width = scrollView.frame.width / downSizeRatio
let height = scrollView.frame.height / downSizeRatio
self.frame = CGRect(x: width * (downSizeRatio - 1), y: height * (downSizeRatio-1), width: width, height: height)

private var dataSource: THMinimapDataSource?

public var minimapImageView: UIImageView?
public var focusedBoxView: UIView?

open func set(dataSource: THMinimapDataSource) {
self.dataSource = dataSource

scrollView.contentInsetAdjustmentBehavior = .never
scrollImageView = UIImageView(frame: CGRect(x: 0, y: 0,
width: scrollView.frame.width,
height: scrollView.frame.height))
Copy link
Contributor

Choose a reason for hiding this comment

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

scrollImageView = UIImageView(frame: CGRect(origin: .zero, size: scrollView.frame.size))

This style looks better for minimizing code.

minimapImageView = UIImageView(frame: CGRect(x: 0, y: 0,
width: dataSource.minimapImageWidth,
height: dataSource.minimapImageHeight))
minimapImageView?.image = dataSource.thumbnailImage
minimapImageView?.contentMode = .scaleAspectFit
width: self.frame.width,
height: self.frame.height))

focusedBoxView = UIView(frame: CGRect(x: 0, y: 0,
width: dataSource.minimapImageWidth,
height: dataSource.minimapImageHeight))
focusedBoxView?.layer.borderWidth = dataSource.borderWidth
focusedBoxView?.layer.borderColor = dataSource.borderColor.cgColor
focusedBoxView = UIView()

self.addSubview(minimapImageView!)
self.addSubview(focusedBoxView!)
scrollView.addSubview(scrollImageView)
self.addSubview(minimapImageView)
self.addSubview(focusedBoxView)

updateConstraints()
scrollImageView.image = image
if let minimapImage = minimapImage {
minimapImageView.image = minimapImage
focusedBoxView.frame = AVMakeRect(aspectRatio: minimapImage.size, insideRect: minimapImageView.bounds)
} else {
minimapImageView.image = image
focusedBoxView.frame = AVMakeRect(aspectRatio: image.size, insideRect: minimapImageView.bounds)
}
scrollImageView.contentMode = .scaleAspectFit
minimapImageView.contentMode = .scaleAspectFit
focusedBoxView.layer.borderWidth = focusedBorderWidth
focusedBoxView.layer.borderColor = focusedBorderColor
}

open override func updateConstraints() {
super.updateConstraints()
self.removeConstraints(self.constraints)

if let dataSource = dataSource {
self.heightAnchor.constraint(equalToConstant: dataSource.minimapImageHeight).isActive = true
self.widthAnchor.constraint(equalToConstant: dataSource.minimapImageWidth).isActive = true

self.trailingAnchor.constraint(equalTo: dataSource.scrollView.trailingAnchor, constant: 50).isActive = true
self.bottomAnchor.constraint(equalTo: dataSource.scrollView.bottomAnchor, constant: 50).isActive = true
public func getScrolledImageView() -> UIImageView {
return scrollImageView
}
public func resize(scrollView: UIScrollView) {
let scrollBox = AVMakeRect(aspectRatio: (scrollImageView.image?.size)!, insideRect: scrollImageView.frame)
let box = AVMakeRect(aspectRatio: (minimapImageView.image?.size)!, insideRect: minimapImageView.frame)
let zoomScale = scrollView.zoomScale
let widthRatio = box.size.width / scrollBox.size.width
let heightRatio = box.size.height / scrollBox.size.height
var newX = (scrollView.contentOffset.x * widthRatio)
var newY = (scrollView.contentOffset.y * heightRatio)
var newWidth = minimapImageView.frame.size.width / zoomScale
var newHeight = minimapImageView.frame.size.height / zoomScale
if box.origin.x > newX {
newWidth -= (box.origin.x - newX)
newX = box.origin.x
}
if box.origin.y > newY {
newHeight -= (box.origin.y - newY)
newY = box.origin.y
}
if (newX + newWidth) > (box.origin.x + box.size.width) {
newWidth = box.size.width - newX + box.origin.x
}
if (newY + newHeight) > (box.origin.y + box.size.height) {
newHeight = box.size.height - newY + box.origin.y
}
focusedBoxView.frame = CGRect(x: newX, y: newY, width: newWidth, height: newHeight)
}
}
Loading