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

Updated for Swift5 compatibility #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions AKMediaViewer/AKImageScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {

public var zoomImageView: UIImageView?

var imageSize: CGSize = CGSizeZero
var pointToCenterAfterResize: CGPoint = CGPointZero
var imageSize: CGSize = CGSize.zero
var pointToCenterAfterResize: CGPoint = CGPoint.zero
var scaleToRestoreAfterResize: CGFloat = 0.0

override public init(frame: CGRect) {
Expand All @@ -23,7 +23,7 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {
showsVerticalScrollIndicator = false
showsHorizontalScrollIndicator = false
bouncesZoom = true
decelerationRate = UIScrollViewDecelerationRateFast
decelerationRate = UIScrollView.DecelerationRate.fast
}

required public init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -58,7 +58,7 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {
return super.frame
}
set (newFrame) {
let sizeChanging: Bool = !CGSizeEqualToSize(newFrame.size, self.frame.size)
let sizeChanging: Bool = !newFrame.size.equalTo(self.frame.size)

if (sizeChanging) {
prepareToResize()
Expand All @@ -74,7 +74,7 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {

// MARK: - Configure scrollView to display new image

public func displayImage(image: UIImage) {
public func displayImage(_ image: UIImage) {
if(zoomImageView == nil) {
self.zoomScale = 1.0

Expand All @@ -87,7 +87,7 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {
configureForImageSize(image.size)
}

func configureForImageSize(imageSize: CGSize) {
func configureForImageSize(_ imageSize: CGSize) {
self.imageSize = imageSize
self.contentSize = imageSize
setMaxMinZoomScalesForCurrentBounds()
Expand Down Expand Up @@ -126,8 +126,8 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {
// MARK: - Rotation support

func prepareToResize() {
let boundsCenter: CGPoint = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
pointToCenterAfterResize = self.convertPoint(boundsCenter, toView: zoomImageView)
let boundsCenter: CGPoint = CGPoint(x: self.bounds.midX, y: self.bounds.midY)
pointToCenterAfterResize = self.convert(boundsCenter, to: zoomImageView)

scaleToRestoreAfterResize = self.zoomScale

Expand All @@ -148,10 +148,10 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {
// Step 2: restore center point, first making sure it is within the allowable range.

// 2a: convert our desired center point back to our own coordinate space
let boundsCenter: CGPoint = self.convertPoint(pointToCenterAfterResize, toView: zoomImageView)
let boundsCenter: CGPoint = self.convert(pointToCenterAfterResize, to: zoomImageView)

// 2b: calculate the content offset that would yield that center point
var offset: CGPoint = CGPointMake(boundsCenter.x - self.bounds.size.width / 2.0, boundsCenter.y - self.bounds.size.height / 2.0)
var offset: CGPoint = CGPoint(x: boundsCenter.x - self.bounds.size.width / 2.0, y: boundsCenter.y - self.bounds.size.height / 2.0)

// 2c: restore offset, adjusted to be within the allowable range
let maxOffset: CGPoint = maximumContentOffset()
Expand All @@ -169,10 +169,10 @@ public class AKImageScrollView : UIScrollView, UIScrollViewDelegate {
func maximumContentOffset() -> CGPoint {
let contentSize: CGSize = self.contentSize
let boundsSize: CGSize = self.bounds.size
return CGPointMake(contentSize.width - boundsSize.width, contentSize.height - boundsSize.height)
return CGPoint(x: contentSize.width - boundsSize.width, y: contentSize.height - boundsSize.height)
}

func minimumContentOffset() -> CGPoint {
return CGPointZero
return CGPoint.zero
}
}
8 changes: 4 additions & 4 deletions AKMediaViewer/AKMediaFocusBasicToolbarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class AKMediaFocusBasicToolbarController : UIViewController {

public override func viewDidLoad() {

doneButton.setTitle(NSLocalizedString("Done", comment: "Done"), forState: UIControlState.Normal)
doneButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
doneButton.setTitle(NSLocalizedString("Done", comment: "Done"), for: UIControl.State())
doneButton.setTitleColor(UIColor.white, for: UIControl.State())
doneButton.backgroundColor = UIColor.init(white: 0, alpha: 0.5)
doneButton.sizeToFit()

doneButton.frame = CGRectInset(self.doneButton.frame, -20, -4)
doneButton.frame = self.doneButton.frame.insetBy(dx: -20, dy: -4)
doneButton.layer.borderWidth = 2
doneButton.layer.cornerRadius = 4
doneButton.layer.borderColor = UIColor.whiteColor().CGColor
doneButton.layer.borderColor = UIColor.white.cgColor
}
}
Loading