Code Monkey home page Code Monkey logo

uiview-glow's People

Contributors

desplesda avatar jamesperlman avatar jkalash avatar orarbel avatar parisba 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  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  avatar

uiview-glow's Issues

The glowing effect is shifted

I'm trying to use this category on a UICollectionViewCell, but I'm getting a glow shifted to the centre and not over the whole cell.

my implementation is : [myCell.contentView startGlowingWithColor:[ColorsFactory redColor] intensity:1.0f];

do you know what am I doing wrong?

ld: symbol(s) not found for architecture i386

setenv IPHONEOS_DEPLOYMENT_TARGET 6.0
setenv PATH 

Undefined symbols for architecture i386:
"OBJC_CLASS$_CABasicAnimation", referenced from:
objc-class-ref in UIView+Glow.o
"OBJC_CLASS$_CAMediaTimingFunction", referenced from:
objc-class-ref in UIView+Glow.o
"_kCAMediaTimingFunctionEaseInEaseOut", referenced from:
-[UIView(Glow) startGlowingWithColor:fromIntensity:toIntensity๐Ÿ”] in UIView+Glow.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The glow stops once the app is backgrounded

The glowing of the views stop when the app is backgrounded and relaunched. I tried reenabling it by calling the same method after the app is resumed without success. Thank you.

High CPU usage after executing startGlowing

Hello,

Thanks for sharing this glowing function. I've been using this library for several months which is running on iOS7 and everything is fine. But after I run it on iOS8, the CPU usage gets abnormally high except that I remove one line code of executing startGlowing. Anyone can run it normally on iOS8?

sincerely,
Corey

Rotation does not work (iOS 8)

Rotation does not seem to work on this category. If the superview rotates, the view's frame changes, but the glowview stays at the old frame and remains a glowing shadow.

I sort of "fixed" this in my own app by adding two helpful methods to UIView+GlowView. One method returns YES if the view is glowing. The other, glowRotate, does nothing if the view is not glowing and rotates it if it is.

- (BOOL)isGlowing {
if (self.glowView)
    return YES;
else
    return NO;

return NO;
}

- (void)glowRotate {
if (self.glowView)
    self.glowView.center = self.center;
}

As well as adding this wacky code to my ViewController.m, that calls it on every subview:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {

    NSArray *viewsToRotate = [self.view subviews];
    for (UIView *v in viewsToRotate) {
        [v glowRotate];

        if (v.subviews)
        {
            NSArray *moreViews = [v subviews];
            for (UIView *y in moreViews) {
                [y glowRotate];
            }
        }
    }
}];
 }

But the glowView really should support rotation, or at least add the methods above to allow the user to tell it to rotate if it is already glowing.

swift 2.3

I update the code to swift 2.3 (it is somehow a downgrade, but someone might find it useful

//
// UIView+Glow.swift
//
// Translated by Mohamad Nabaa on 20/10/16.
//

import UIKit
import ObjectiveC
private var GLOWVIEW_KEY = "GLOWVIEW"

extension UIView {
var glowView: UIView? {
get {
return objc_getAssociatedObject(self, &GLOWVIEW_KEY) as? UIView
}
set(newGlowView) {
objc_setAssociatedObject(self, &GLOWVIEW_KEY, newGlowView!, .OBJC_ASSOCIATION_RETAIN)
}
}

func startGlowingWithColor(color:UIColor, intensity:CGFloat) {
    self.startGlowingWithColor(color, fromIntensity: 0.1, toIntensity: intensity, repeat: true)
}

func startGlowingWithColor(color:UIColor, fromIntensity:CGFloat, toIntensity:CGFloat, repeat shouldRepeat:Bool) {
    // If we're already glowing, don't bother
    if self.glowView != nil {
        return
    }

    // The glow image is taken from the current view's appearance.
    // As a side effect, if the view's content, size or shape changes,
    // the glow won't update.
    var image:UIImage






    UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, UIScreen.mainScreen().scale); do {
        self.layer.renderInContext(UIGraphicsGetCurrentContext()!)
        let path = UIBezierPath(rect: CGRect(x: 0, y: 0, width: self.bounds.size.width, height: self.bounds.size.height))

        color.setFill()
        path.fillWithBlendMode(.SourceAtop, alpha: 1.0)


        image = UIGraphicsGetImageFromCurrentImageContext()!
    }

    UIGraphicsEndImageContext()

    // Make the glowing view itself, and position it at the same
    // point as ourself. Overlay it over ourself.
    let glowView = UIImageView(image: image)
    glowView.center = self.center
    self.superview!.insertSubview(glowView, aboveSubview:self)

    // We don't want to show the image, but rather a shadow created by
    // Core Animation. By setting the shadow to white and the shadow radius to
    // something large, we get a pleasing glow.
    glowView.alpha = 0
    glowView.layer.shadowColor = color.CGColor
    glowView.layer.shadowOffset = CGSize.zero
    glowView.layer.shadowRadius = 10
    glowView.layer.shadowOpacity = 1.0

    // Create an animation that slowly fades the glow view in and out forever.
    let animation = CABasicAnimation(keyPath: "opacity")
    animation.fromValue = fromIntensity
    animation.toValue = toIntensity
    animation.repeatCount = shouldRepeat ? .infinity : 0 // HUGE_VAL = .infinity / Thanks http://stackoverflow.com/questions/7082578/cabasicanimation-unlimited-repeat-without-huge-valf
    animation.duration = 1.0
    animation.autoreverses = true
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    glowView.layer.addAnimation(animation, forKey: "pulse")


    // Finally, keep a reference to this around so it can be removed later
    self.glowView = glowView
}

func glowOnceAtLocation(point: CGPoint, inView view:UIView) {
    self.startGlowingWithColor(UIColor.whiteColor(), fromIntensity: 0, toIntensity: 0.6, repeat: false)

    self.glowView!.center = point
    view.addSubview(self.glowView!)

    let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
    dispatch_after(dispatchTime, dispatch_get_main_queue(), {
        self.stopGlowing()
    })




}

func glowOnce() {
    self.startGlowing()

    let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
    dispatch_after(dispatchTime, dispatch_get_main_queue(), {
        self.stopGlowing()
    })

}

// Create a pulsing, glowing view based on this one.
func startGlowing() {
    self.startGlowingWithColor(UIColor.whiteColor(), intensity:0.6);
}

// Stop glowing by removing the glowing view from the superview
// and removing the association between it and this object.
func stopGlowing() {
    self.glowView!.removeFromSuperview()
    self.glowView = nil
}

}

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.