Club 15CC

Graphics ~ 15CC Code

Task Code
iOS Get iPhone/iPad Screen Dimensions »
CGSize screenSize = UIScreen.mainScreen.applicationFrame.size;
iOS Add a pulsating image to a new CALayer centred on an existing view. »
// Somewhere in the setup code, possible awakeFromNib if relevant. NOT in drawRect:!

UIImage *img = [UIImage imageNamed:@"BigHand"];
UIGraphicsBeginImageContext(img.size);
[img drawAtPoint:CGPointMake(0, 0)]; // handy!

CALayer *newLayer = [CALayer layer];
newLayer.bounds = CGRectMake(0, 0, img.size.width, img.size.height);
newLayer.position = CGPointMake(self.layer.bounds.size.width/2.0, self.layer.bounds.size.height/2.0); // centred
newLayer.contentsScale = self.layer.contentsScale; // for retina compat. Make sure you've set you view's main layer
newLayer.contents = (__bridge id)UIGraphicsGetImageFromCurrentImageContext().CGImage;
newLayer.opacity = 1.0;
UIGraphicsEndImageContext();

// Create the animation...
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.fromValue = [NSNumber numberWithFloat:0.6];
anim.toValue = [NSNumber numberWithFloat:1.0];
anim.duration = 0.7;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.autoreverses = YES;
anim.repeatCount = HUGE_VALF; // repeat forever
[newLayer addAnimation:anim forKey:@"opacity"];

[self.layer addSublayer:newLayer];
iOS Manually load an image into a UIView’s layer »
NSString *image = [[NSBundle mainBundle] pathForResource:@"GoldRing" ofType:@"png"];
self.layer.contents = (id)[[UIImage imageWithContentsOfFile:image] CGImage];

// or simply...
self.layer.contents = [[UIImage imageNamed:@"GoldRing"] CGImage];
iOS Get the size of a UIView (from a UIViewController) »
self.view.bounds.size.width