Skip to content

Commit 9ee8459

Browse files
committed
2.0.4
1 parent c63c120 commit 9ee8459

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
## [Version 2.0.4](https://github.com/efremidze/Magnetic/releases/tag/2.0.4)
4+
Released on 2017-12-13
5+
6+
- Image bugs fix
7+
38
## [Version 2.0.3](https://github.com/efremidze/Magnetic/releases/tag/2.0.3)
49
Released on 2017-12-10
510

Magnetic.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'Magnetic'
11-
s.version = '2.0.3'
11+
s.version = '2.0.4'
1212
s.summary = 'SpriteKit Floating Bubble Picker (inspired by Apple Music)'
1313
s.homepage = 'https://github.com/efremidze/Magnetic'
1414
s.license = { :type => 'MIT', :file => 'LICENSE' }

Sources/Extensions.swift

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,24 @@ extension CGPoint {
2020
}
2121
}
2222

23-
extension SKSpriteNode {
24-
func aspectFill(size: CGSize) {
25-
let _size = self.size
26-
let verticalRatio = _size.height / size.height
27-
let horizontalRatio = _size.width / size.width
28-
let scaleRatio = horizontalRatio > verticalRatio ? horizontalRatio : verticalRatio
29-
self.setScale(scaleRatio)
30-
self.size = size
23+
extension UIImage {
24+
func aspectFill(_ size: CGSize) -> UIImage {
25+
let aspectWidth = size.width / self.size.width
26+
let aspectHeight = size.height / self.size.height
27+
let aspectRatio = max(aspectWidth, aspectHeight)
28+
29+
var newSize = self.size
30+
newSize.width *= aspectRatio
31+
newSize.height *= aspectRatio
32+
return resize(newSize)
33+
}
34+
func resize(_ size: CGSize) -> UIImage {
35+
var rect = CGRect.zero
36+
rect.size = size
37+
UIGraphicsBeginImageContextWithOptions(size, false, scale)
38+
draw(in: rect)
39+
let image = UIGraphicsGetImageFromCurrentImageContext()
40+
UIGraphicsEndImageContext()
41+
return image!
3142
}
3243
}

Sources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.0.3</string>
18+
<string>2.0.4</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Sources/Node.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ open class Node: MaskNode {
4343
*/
4444
open var image: UIImage? {
4545
didSet {
46-
texture = image.map { SKTexture(image: $0) }
47-
sprite.aspectFill(size: texture?.size() ?? self.frame.size)
46+
// let url = URL(string: "https://picsum.photos/1200/600")!
47+
// let image = UIImage(data: try! Data(contentsOf: url))
48+
texture = image.map { SKTexture(image: $0.aspectFill(self.frame.size)) }
49+
sprite.size = texture?.size() ?? self.frame.size
4850
}
4951
}
5052

0 commit comments

Comments
 (0)