GithubHelp home page GithubHelp logo

ypmagnifyingglass's People

Contributors

gjnilsen avatar skyeroad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ypmagnifyingglass's Issues

Swift 3.0

I have followed your instruction its working for me.

Swift 2.0

Some modifications are needed for this to work properly in Swift 2.0
`//
// YPMagnifyingView.swift
// YPMagnifyingGlass
//
// Created by Geert-Jan Nilsen on 02/06/15.
// Copyright (c) 2015 Yuppielabel.com All rights reserved.
//

import UIKit

public class YPMagnifyingView: UIView {

public var YPMagnifyingViewDefaultShowDelay: NSTimeInterval = 0.2;

private var magnifyingGlassShowDelay: NSTimeInterval

private var touchTimer: NSTimer!

public var magnifyingGlass: YPMagnifyingGlass = YPMagnifyingGlass()

override public init(frame: CGRect) {
self.magnifyingGlassShowDelay = YPMagnifyingViewDefaultShowDelay
super.init(frame: frame)
}

required public init?(coder aDecoder: NSCoder) {
self.magnifyingGlassShowDelay = YPMagnifyingViewDefaultShowDelay
super.init(coder: aDecoder)
}

// MARK: - Touch Events
override public func touchesBegan(touches: Set, withEvent event: UIEvent?) {
if let touch: UITouch = touches.first {

  self.touchTimer = NSTimer.scheduledTimerWithTimeInterval(magnifyingGlassShowDelay, target: self, selector: Selector("addMagnifyingGlassTimer:"), userInfo: NSValue(CGPoint: touch.locationInView(self)), repeats: false)
}

}

override public func touchesMoved(touches: Set, withEvent event: UIEvent?) {
if let touch: UITouch = touches.first {
self.updateMagnifyingGlassAtPoint(touch.locationInView(self))
}
}

override public func touchesEnded(touches: Set, withEvent event: UIEvent?) {
self.touchTimer.invalidate()
self.touchTimer = nil

self.removeMagnifyingGlass()

}

// MARK: - Private Functions

private func addMagnifyingGlassAtPoint(point: CGPoint) {
self.magnifyingGlass.viewToMagnify = self as UIView
self.magnifyingGlass.touchPoint = point

let selfView: UIView = self as UIView

// let superView: UIView = self.superview!

selfView.addSubview(self.magnifyingGlass)

self.magnifyingGlass.setNeedsDisplay()

}

private func removeMagnifyingGlass() {
self.magnifyingGlass.removeFromSuperview()
}

private func updateMagnifyingGlassAtPoint(point: CGPoint) {
self.magnifyingGlass.touchPoint = point
self.magnifyingGlass.setNeedsDisplay()
}

public func addMagnifyingGlassTimer(timer: NSTimer) {
let value: AnyObject? = timer.userInfo
if let point = value?.CGPointValue {
self.addMagnifyingGlassAtPoint(point)
}
}
}
//
// YPMagnifyingGlass.swift
// YPMagnifyingGlass
//
// Created by Geert-Jan Nilsen on 02/06/15.
// Copyright (c) 2015 Yuppielabel.com All rights reserved.
//

import UIKit
import QuartzCore

public class YPMagnifyingGlass: UIView {

public var viewToMagnify: UIView!
public var touchPoint: CGPoint! {
didSet {
self.center = CGPointMake(touchPoint.x + touchPointOffset.x, touchPoint.y + touchPointOffset.y)
}
}

public var touchPointOffset: CGPoint!
public var scale: CGFloat!
public var scaleAtTouchPoint: Bool!

public var YPMagnifyingGlassDefaultRadius: CGFloat = 40.0
public var YPMagnifyingGlassDefaultOffset: CGFloat = -40.0
public var YPMagnifyingGlassDefaultScale: CGFloat = 2.0

public func initViewToMagnify(viewToMagnify: UIView, touchPoint: CGPoint, touchPointOffset: CGPoint, scale: CGFloat, scaleAtTouchPoint: Bool) {

self.viewToMagnify = viewToMagnify
self.touchPoint = touchPoint
self.touchPointOffset = touchPointOffset
self.scale = scale
self.scaleAtTouchPoint = scaleAtTouchPoint

}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

required public override init(frame: CGRect) {
super.init(frame: frame)

self.layer.borderColor = UIColor.lightGrayColor().CGColor
self.layer.borderWidth = 3
self.layer.cornerRadius = frame.size.width / 2
self.layer.masksToBounds = true
self.touchPointOffset = CGPointMake(0, YPMagnifyingGlassDefaultOffset)
self.scale = YPMagnifyingGlassDefaultScale
self.viewToMagnify = nil
self.scaleAtTouchPoint = true

}

private func setFrame(frame: CGRect) {
super.frame = frame
self.layer.cornerRadius = frame.size.width / 2
}

public override func drawRect(rect: CGRect) {
let context: CGContextRef = UIGraphicsGetCurrentContext()!
CGContextTranslateCTM(context, self.frame.size.width/2, self.frame.size.height/2)
CGContextScaleCTM(context, self.scale, self.scale)
CGContextTranslateCTM(context, -self.touchPoint.x, -self.touchPoint.y + (self.scaleAtTouchPoint != nil ? 0 : self.bounds.size.height/2))
self.viewToMagnify.layer.renderInContext(context)
}
}
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.