Skip to content

Instantly share code, notes, and snippets.

@MaximAlien
Created November 4, 2015 15:27
Show Gist options
  • Save MaximAlien/e91d5b15de8f3d73055c to your computer and use it in GitHub Desktop.
Save MaximAlien/e91d5b15de8f3d73055c to your computer and use it in GitHub Desktop.
[iOS] [CAAnimation] Simple animation of the view
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 50, 50)];
[view setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:view];
CABasicAnimation *animation = [CABasicAnimation animation];
animation.keyPath = @"position.x";
animation.fromValue = @0;
animation.toValue = @(self.view.frame.size.width);
animation.duration = 1;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = YES;
[view.layer addAnimation:animation forKey:@"basic"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment