-
-
Save k06a/4e46efb2f7ba6e5649805ed75b63620d to your computer and use it in GitHub Desktop.
contentsRect animation
This file contains 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 <QuartzCore/QuartzCore.h> | |
#import "Bike.h" | |
@implementation Bike { | |
} | |
- (id)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
if (self) { | |
[self prepare]; | |
} | |
return self; | |
} | |
- (void)prepare { | |
CALayer *layer = [CALayer layer]; | |
layer.backgroundColor = [[UIColor redColor] CGColor]; | |
layer.frame = self.bounds; | |
layer.borderWidth = 10; | |
UIGraphicsBeginImageContext(self.bounds.size); | |
[layer renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
self.layer.contents = (__bridge id) [image CGImage]; | |
// CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; | |
// [animation setFromValue:[NSValue valueWithCGPoint:CGPointMake(100, 50)]]; | |
// [animation setToValue:[NSValue valueWithCGPoint:CGPointMake(600, 50)]]; | |
// [animation setDuration:60]; | |
// [layer addAnimation:animation forKey:@"michal"]; | |
self.layer.contentsRect = CGRectMake(0, 0, 0, 0); | |
CGRect beginRect = CGRectMake(0, 0, 0.5, 0.5); | |
CGRect endRect = CGRectMake(0, 0, 1, 1); | |
CABasicAnimation *contentsRectAnim = [CABasicAnimation animationWithKeyPath:@"contentsRect"]; | |
contentsRectAnim.fromValue = [NSValue valueWithCGRect:beginRect]; | |
contentsRectAnim.toValue = [NSValue valueWithCGRect:endRect]; | |
contentsRectAnim.duration = 10.0; | |
[self.layer addAnimation:contentsRectAnim forKey:@"michal"]; | |
self.layer.contentsRect =endRect; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment