Skip to content

Instantly share code, notes, and snippets.

View quangtqag's full-sized avatar
🚀
Researching things that I am lacking...

Quang quangtqag

🚀
Researching things that I am lacking...
View GitHub Profile
//
// Reference: https://www.raywenderlich.com/79150/grand-central-dispatch-tutorial-swift-part-2
//
var GlobalMainQueue: dispatch_queue_t {
return dispatch_get_main_queue()
}
var GlobalUserInteractiveQueue: dispatch_queue_t {
return dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.value), 0)
//
// Reference from http://samwize.com/2015/11/06/guide-to-customizing-uitableview-section-header-footer/
//
class TableSectionHeader: UITableViewHeaderFooterView {
@IBOutlet weak var titleLabel: UILabel!
}
let nib = UINib(nibName: "TableSectionHeader", bundle: nil)
tableView.registerNib(nib, forHeaderFooterViewReuseIdentifier: "TableSectionHeader")
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.separatorInset = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 0)
}
class MyView: UIView {
@IBOutlet weak var label: UILabel!
class func instanceFromNib() -> MyView {
return UINib(nibName: "MyView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! MyView
}
}
func getSearchTextField() -> UITextField {
return valueForKey("_searchField") as! UITextField
}
extension UIView {
func allConstraints() -> [NSLayoutConstraint] {
var constraints = [NSLayoutConstraint]()
constraints += self.constraints
var superview = self.superview
while superview != nil {
for c in superview!.constraints {
if c.firstItem as? UIView == self || c.secondItem as? UIView == self {
constraints.append(c)
NSLayoutConstraint.activateConstraints(constraints)
UIView.animateWithDuration(0.5) {
self.view.layoutIfNeeded()
}
import AVFoundation
private func showDialogWithTitle(title: String?, msg: String?) {
let alertController = UIAlertController(title: title, message: msg, preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
@IBAction func didTapButton(sender: AnyObject) {
let authorizationStatus: AVAuthorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
func fixOrientation() -> UIImage {
// No-op if the orientation is already correct
if ( self.imageOrientation == UIImageOrientation.Up ) {
return self;
}
// We need to calculate the proper transformation to make the image upright.
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
var transform: CGAffineTransform = CGAffineTransformIdentity
let asset = AVURLAsset(URL: NSURL(string: self.scheduleCelebrityGame.videoLink!)!, options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
do {
let cgImage = try imgGenerator.copyCGImageAtTime(CMTimeMake(0, 1), actualTime: nil)
let uiImage = UIImage(CGImage: cgImage, scale: CGFloat(1.0), orientation: UIImageOrientation.Right)
let uiImageJPEG = UIImageJPEGRepresentation(uiImage, 1.0)!
} catch {
}