// // ViewExtensions.swift // Sirani // // Created by Anhar Solehudin on 30/03/19. // Copyright © 2019 Anhar Solehudin. All rights reserved. // import UIKit extension UIView { // show / hide view func show() { isHidden = false } func hide() { isHidden = true } // add auto layout contraints on view func anchor(top: NSLayoutYAxisAnchor?, bottom: NSLayoutYAxisAnchor?, leading: NSLayoutXAxisAnchor?, trailing: NSLayoutXAxisAnchor?, padding: UIEdgeInsets = .zero, size: CGSize = .zero) { translatesAutoresizingMaskIntoConstraints = false if size.width > 0 { widthAnchor.constraint(equalToConstant: size.width).isActive = true } if size.height > 0 { heightAnchor.constraint(equalToConstant: size.height).isActive = true } if let top = top { topAnchor.constraint(equalTo: top, constant: padding.top).isActive = true } if let bottom = bottom { bottomAnchor.constraint(equalTo: bottom, constant: -padding.bottom).isActive = true } if let leading = leading { leadingAnchor.constraint(equalTo: leading, constant: padding.left).isActive = true } if let trailing = trailing { trailingAnchor.constraint(equalTo: trailing, constant: -padding.right).isActive = true } } // rotate view func rotate(_ toValue: CGFloat, duration: CFTimeInterval = 0.3) { let animation = CABasicAnimation(keyPath: "transform.rotation") animation.toValue = toValue animation.duration = duration animation.isRemovedOnCompletion = false animation.fillMode = CAMediaTimingFillMode.forwards self.layer.add(animation, forKey: nil) } }