Aggiungere un tremolio a un'immagine (wiggle) (aggiungere QuartzCore FrameWork)

Send Snippet To: Save this snippet to Code Collector Pro -- view all powidl's snippets
language: Objective-C
license: Other

Code for Snippet:

-(void)doWiggle:(UIView *)touchView {
	// grabbing the layer of the tocuhed view.
	CALayer *touchedLayer = [touchView layer];
	// here is an example wiggle
	CABasicAnimation *wiggle = [CABasicAnimation animationWithKeyPath:@"transform"];
	wiggle.duration = 0.1;
	wiggle.repeatCount = 1e100f;
	wiggle.autoreverses = YES;
	wiggle.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(touchedLayer.transform,0.1, 0.0 ,1.0 ,2.0)];
	// doing the wiggle
	[touchedLayer addAnimation:wiggle forKey:@"wiggle"];
	// setting a timer to remove the layer
	NSTimer *wiggleTimer = [NSTimer scheduledTimerWithTimeInterval:(2) target:self selector:@selector(endWiggle:) userInfo:touchedLayer repeats:NO];
-(void)endWiggle:(NSTimer*)timer {
	// stopping the wiggle now
	[((CALayer*)timer.userInfo) removeAllAnimations];
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [[event allTouches] anyObject];
	if ([touch view] == image) {
		[self doWiggle:[touch view]];
	else if ([touch view] == image2) {
		[self doWiggle:[touch view]];
comments powered by Disqus


Link to this snippet:

Download to Code Collector

To use the direct link to your snippet on either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 656
Date Added: 2009-03-02 10:41:32
Last Modified: 0000-00-00 00:00:00

Web Analytics