|
iOS
Present Your UIView Subview With a 3D Flip »
|
// Somewhere in your UIView...
self.layer.transform = CATransform3DMakeRotation(-90.0f*M_PI/180.f, 1.0, 1.0, 0.0); // start: hidden at 90deg
CATransform3D trans3D = CATransform3DMakeRotation(0.0f*M_PI/180.f, 1.0, 1.0, 0.0); // end: angle and rotation vector (axis)
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
transformAnimation.removedOnCompletion = NO;
transformAnimation.toValue = [NSValue valueWithCATransform3D:trans3D];
transformAnimation.fillMode = kCAFillModeForwards;
[self.layer addAnimation:transformAnimation forKey:@"transform"]; |
|
jQuery
Smoothscroll for anchor links with jQuery »
Many thx:...
|
jQuery(function ($) {
var SMOOTHSCROLL_MARGIN = 12;
$(".smoothscroll").click(function(evt){console.log('s');
evt.preventDefault();
var offset = $($(this).attr('href')).offset().top - SMOOTHSCROLL_MARGIN;
$('html, body').animate({scrollTop:offset}, 500);
});
});
|
|
iOS
Temporarily remove an implicit animation on a CALayer object »
`action` is empty initially which uses the UIKit...
|
// Turn off the implicit animation for the touchHint layer
NSMutableDictionary *actions = [NSMutableDictionary dictionaryWithDictionary:touchHint.actions];
[actions setObject:[NSNull null] forKey:@"position"];
touchHint.actions = actions;
// Restore the implicit animation
NSMutableDictionary *actions = [NSMutableDictionary dictionaryWithDictionary:touchHint.actions];
[actions removeObjectForKey:@"position"];
touchHint.actions = actions; |
|
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]; |