This file contains hidden or 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
// | |
// CustomDynamicAlertView.h | |
// Week3_inclass | |
// | |
// Created by Victor Baro on 18/02/2015. | |
// Copyright (c) 2015 Produkt. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> |
This file contains hidden or 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 | |
class ViewController: UIViewController { | |
let magicLabel = AnimatedLabel(frame: CGRectMake(100, 100, 300, 20)); | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
magicLabel.text = "Magic label" | |
self.view.addSubview(magicLabel); |
This file contains hidden or 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
@IBAction func viewDragged(sender: UIPanGestureRecognizer) { | |
let yTranslation = sender.translationInView(view).y | |
if (hasExceededVerticalLimit(topViewConstraint.constant)){ | |
totalTranslation += yTranslation | |
topViewConstraint.constant = logConstraintValueForYPoisition(totalTranslation) | |
if(sender.state == UIGestureRecognizerState.Ended ){ | |
animateViewBackToLimit() | |
} | |
} else { | |
topViewConstraint.constant += yTranslation |
This file contains hidden or 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.UIGestureRecognizerSubclass | |
class ForceGestureRecognizer: UIGestureRecognizer { | |
var forceValue: CGFloat = 0 | |
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent) { | |
super.touchesBegan(touches, withEvent: event) | |
state = .Began | |
handleForceWithTouches(touches) |
This file contains hidden or 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
func imagePressed(sender: ForceGestureRecognizer) { | |
let point = sender.locationInView(self.view) | |
let imageCoordPoint = CGPointMake(point.x - initialFrame.origin.x, point.y - initialFrame.origin.y) | |
var xValue = max(0, imageCoordPoint.x / initialFrame.size.width) | |
var yValue = max(0, imageCoordPoint.y / initialFrame.size.height) | |
xValue = min(xValue, 1) | |
yValue = min(yValue, 1) | |
This file contains hidden or 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 class MagnifyingView: UIView { | |
private weak var viewToMagnify: UIView! | |
private var touchPoint: CGPoint! | |
var zoomScale: CGFloat = 2 | |
public required init?(coder aDecoder: NSCoder) { fatalError() } | |
public init(viewToMagnify: UIView, size: CGSize) { | |
self.viewToMagnify = viewToMagnify | |
super.init(frame: CGRect(origin: .zero, size: size)) |
This file contains hidden or 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
class ViewController: UIViewController { | |
//Set your views and long press recognizer to magnifyControlView | |
private func handleMagnify(_ recognizer: UILongPressGestureRecognizer) { | |
let point = recognizer.location(in: magnifyControlView).multiplyValues(by: controlScale) | |
switch recognizer.state { | |
case .began: | |
magnifyView = MagnifyingView(viewToMagnify: comicPageImageView, size: CGSize(width: 200, height: 200)) |
This file contains hidden or 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
class PaddingLabel: UILabel { | |
var padding: UIEdgeInsets { | |
didSet { | |
invalidateIntrinsicContentSize() | |
} | |
} | |
public required init(padding: UIEdgeInsets = .zero) { | |
self.padding = padding | |
super.init(frame: CGRect.zero) |
This file contains hidden or 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 Array { | |
func grouped<T: Equatable>(by value: (Element) -> T) -> [[Element]] { | |
var result = [[Element]]() | |
for element in self { | |
var foundIndex: Int? | |
for (index, internalArray) in result.enumerated() { | |
if let firstValue = internalArray.first, value(firstValue) == value(element) { | |
foundIndex = index | |
continue | |
} |
OlderNewer