Skip to content

Commit

Permalink
Merge pull request #48 from omaralbeik/development
Browse files Browse the repository at this point in the history
fix: Fixed UIViewExtensions bugs
  • Loading branch information
omaralbeik committed Dec 14, 2016
2 parents 9440bdc + bd65cd9 commit 8b0d6d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
2 changes: 1 addition & 1 deletion SwifterSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "SwifterSwift"
spec.version = "1.3.5"
spec.version = "1.3.6"
spec.summary = "A handy collection of more than 370 native Swift 3 extensions to boost your productivity."
spec.description = <<-DESC
SwifterSwift is a library of over 370 properties and methods for more than 36 types, designed to extend Swift's functionality and productivity, staying faithful to the original design guidelines of swift 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
// MARK: - Methods
public extension UINavigationItem {

/// SwifterSwift: Replace title label with an image in naivgation item.
/// SwifterSwift: Replace title label with an image in navigation item.
///
/// - Parameter image: UIImage to replace title with.
public func replaceTitle(with image: UIImage) {
Expand Down
55 changes: 23 additions & 32 deletions SwifterSwift/SwifterSwift/Extensions/UI/UIViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,6 @@ public extension UIView {
}
}

/// SwifterSwift: Check if view is visible in screen currently and not hidden.
public var isVisible: Bool {
// https://github.com/hilen/TimedSilver/blob/master/Sources/UIKit/UIView%2BTSExtension.swift
if self.window == nil || self.isHidden || self.alpha == 0 {
return true
}
let viewRect = self.convert(self.bounds, to: nil)
guard let window = UIApplication.shared.keyWindow else {
return true
}
return viewRect.intersects(window.bounds) == false
}

/// SwifterSwift: Take screenshot of view (if applicable).
public var screenshot: UIImage? {
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, 0.0);
Expand Down Expand Up @@ -191,7 +178,7 @@ public extension UIView {
}
}

// SwifterSwift: Size of view.
/// SwifterSwift: Size of view.
public var size: CGSize {
get {
return self.frame.size
Expand All @@ -202,7 +189,19 @@ public extension UIView {
}
}

// SwifterSwift: Width of view.
/// SwifterSwift: Get view's parent view controller
public var parentViewController: UIViewController? {
weak var parentResponder: UIResponder? = self
while parentResponder != nil {
parentResponder = parentResponder!.next
if let viewController = parentResponder as? UIViewController {
return viewController
}
}
return nil
}

/// SwifterSwift: Width of view.
public var width: CGFloat {
get {
return self.frame.size.width
Expand Down Expand Up @@ -267,7 +266,7 @@ public extension UIView {
self.isHidden = false
}
UIView.animate(withDuration: duration, animations: {
self.alpha = 0
self.alpha = 1
}, completion: completion)
}

Expand All @@ -281,7 +280,7 @@ public extension UIView {
self.isHidden = false
}
UIView.animate(withDuration: duration, animations: {
self.alpha = 1
self.alpha = 0
}, completion: completion)
}

Expand Down Expand Up @@ -315,14 +314,10 @@ public extension UIView {
/// - completion: optional completion handler to run with animation finishes (default is nil).
public func rotate(byAngle angle : CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion:((Bool) -> Void)? = nil) {
let angleWithType = (type == .degrees) ? CGFloat(M_PI) * angle / 180.0 : angle
if animated {
UIView.animate(withDuration: duration, delay: 0, options: .curveLinear, animations: { () -> Void in
self.transform = self.transform.rotated(by: angleWithType)
}, completion: completion)
} else {
let aDuration = animated ? duration : 0
UIView.animate(withDuration: aDuration, delay: 0, options: .curveLinear, animations: { () -> Void in
self.transform = self.transform.rotated(by: angleWithType)
completion?(true)
}
}, completion: completion)
}

/// SwifterSwift: Rotate view to angle on fixed axis.
Expand All @@ -335,14 +330,10 @@ public extension UIView {
/// - completion: optional completion handler to run with animation finishes (default is nil).
public func rotate(toAngle angle: CGFloat, ofType type: AngleUnit, animated: Bool = false, duration: TimeInterval = 1, completion:((Bool) -> Void)? = nil) {
let angleWithType = (type == .degrees) ? CGFloat(M_PI) * angle / 180.0 : angle
if animated {
UIView.animate(withDuration: duration, animations: {
self.transform = CGAffineTransform(rotationAngle: angleWithType)
}, completion: completion)
} else {
transform = CGAffineTransform(rotationAngle: angleWithType)
completion?(true)
}
let aDuration = animated ? duration : 0
UIView.animate(withDuration: aDuration, animations: {
self.transform = self.transform.concatenating(CGAffineTransform(rotationAngle: angleWithType))
}, completion: completion)
}

/// SwifterSwift: Scale view by offset.
Expand Down
2 changes: 1 addition & 1 deletion SwifterSwift/SwifterSwift/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>1.3.5</string>
<string>1.3.6</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down

0 comments on commit 8b0d6d6

Please sign in to comment.