Skip to content

Commit

Permalink
2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lasha-ring committed Dec 14, 2017
1 parent c63c120 commit 9ee8459
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## [Version 2.0.4](https://github.com/efremidze/Magnetic/releases/tag/2.0.4)
Released on 2017-12-13

- Image bugs fix

## [Version 2.0.3](https://github.com/efremidze/Magnetic/releases/tag/2.0.3)
Released on 2017-12-10

Expand Down
2 changes: 1 addition & 1 deletion Magnetic.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Magnetic'
s.version = '2.0.3'
s.version = '2.0.4'
s.summary = 'SpriteKit Floating Bubble Picker (inspired by Apple Music)'
s.homepage = 'https://github.com/efremidze/Magnetic'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
27 changes: 19 additions & 8 deletions Sources/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ extension CGPoint {
}
}

extension SKSpriteNode {
func aspectFill(size: CGSize) {
let _size = self.size
let verticalRatio = _size.height / size.height
let horizontalRatio = _size.width / size.width
let scaleRatio = horizontalRatio > verticalRatio ? horizontalRatio : verticalRatio
self.setScale(scaleRatio)
self.size = size
extension UIImage {
func aspectFill(_ size: CGSize) -> UIImage {
let aspectWidth = size.width / self.size.width
let aspectHeight = size.height / self.size.height
let aspectRatio = max(aspectWidth, aspectHeight)

var newSize = self.size
newSize.width *= aspectRatio
newSize.height *= aspectRatio
return resize(newSize)
}
func resize(_ size: CGSize) -> UIImage {
var rect = CGRect.zero
rect.size = size
UIGraphicsBeginImageContextWithOptions(size, false, scale)
draw(in: rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
}
2 changes: 1 addition & 1 deletion Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.0.3</string>
<string>2.0.4</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
6 changes: 4 additions & 2 deletions Sources/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ open class Node: MaskNode {
*/
open var image: UIImage? {
didSet {
texture = image.map { SKTexture(image: $0) }
sprite.aspectFill(size: texture?.size() ?? self.frame.size)
// let url = URL(string: "https://picsum.photos/1200/600")!
// let image = UIImage(data: try! Data(contentsOf: url))
texture = image.map { SKTexture(image: $0.aspectFill(self.frame.size)) }

This comment has been minimized.

Copy link
@alexandre-g

alexandre-g Dec 14, 2017

Is there something I don't know, or is the image.map { } redundant?
texture = SKTexture(image: image.aspectFill(self.frame.size)))

This comment has been minimized.

Copy link
@efremidze

efremidze Dec 14, 2017

Owner

image can't be nil if u call it like that.
image.map is correct.

sprite.size = texture?.size() ?? self.frame.size
}
}

Expand Down

0 comments on commit 9ee8459

Please sign in to comment.