This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WebKit | |
class NativeWebViewController: UIViewController { | |
let viewportScriptString = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); meta.setAttribute('initial-scale', '1.0'); meta.setAttribute('maximum-scale', '1.0'); meta.setAttribute('minimum-scale', '1.0'); meta.setAttribute('user-scalable', 'no'); document.getElementsByTagName('head')[0].appendChild(meta);" | |
let disableSelectionScriptString = "document.documentElement.style.webkitUserSelect='none';" | |
let disableCalloutScriptString = "document.documentElement.style.webkitTouchCallout='none';" | |
override func viewDidLoad() { | |
// 1 - Make user scripts for injection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Generate thumbnail with AVAssetImageGenerator | |
func generateThumbnailFromAsset(asset: AVAsset, forTime time: CMTime) -> UIImage { | |
let imageGenerator = AVAssetImageGenerator(asset: asset) | |
imageGenerator.appliesPreferredTrackTransform = true | |
var actualTime: CMTime = kCMTimeZero | |
do { | |
let imageRef = try imageGenerator.copyCGImageAtTime(time, actualTime: &actualTime) | |
let image = UIImage(CGImage: imageRef) | |
return image | |
} catch let error as NSError { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* This class provides a UIViewController extension which adds a tag property to all UIViewController subclasses. | |
* | |
*/ | |
import Foundation | |
private var tagAssociationKey: UInt8 = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let shadowPath = UIBezierPath(rect: self.myView.layer.bounds) | |
self.myView.layer.masksToBounds = false | |
self.myView.layer.shadowColor = UIColor.blackColor().CGColor | |
self.myView.layer.shadowOffset = CGSizeMake(0.0, -2.0) | |
self.myView.layer.shadowOpacity = 0.3 | |
self.myView.layer.shadowRadius = 1.0 | |
self.myView.layer.shadowPath = shadowPath.CGPath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIViewController { | |
func isVisible() -> Bool { | |
return self.isViewLoaded() && self.view.window != nil | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIView { | |
/** | |
Set a shadow on a UIView. | |
- parameters: | |
- color: Shadow color, defaults to black | |
- opacity: Shadow opacity, defaults to 1.0 | |
- offset: Shadow offset, defaults to zero | |
- radius: Shadow radius, defaults to 0 | |
- viewCornerRadius: If the UIView has a corner radius this must be set to match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Function that locks an object while it is being acted upon in the closure parameter. | |
Rethrows allows the function to throw an error for throwing closures or not for non-throwing closures (do not need `try` for non-throwing closures). | |
parameter lock: Object to be sync'd | |
parameter closure: Code of critical section | |
*/ | |
public func synchronized<T>(lock: AnyObject, @noescape closure: () throws -> T) rethrows -> T { | |
objc_sync_enter(lock) | |
defer { | |
objc_sync_exit(lock) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
/** | |
UIView subclass that is transparent to all touch events besides those on eligible child views. | |
*/ | |
class TKPassThroughView: UIView { | |
// MARK - Touch Handling | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIResponder+FirstResponder.swift | |
// Thor | |
// | |
// Created by Max Campolo on 8/20/17. | |
// Copyright © 2017 Max Campolo. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override func layoutSubviews() { | |
super.layoutSubviews() | |
// If the view is animating apply the animation to the sublayer | |
CATransaction.begin() | |
if let animation = layer.animationForKey("position") { | |
CATransaction.setAnimationDuration(animation.duration) | |
CATransaction.setAnimationTimingFunction(animation.timingFunction) | |
} else { | |
CATransaction.disableActions() |
NewerOlder