使图片自动移动的方法
- (void)setOffSetAnimation:(UIImageView *)imageView Duration:(NSInteger)duration{
NSInteger imageHeight = imageView.image.size.height;
NSInteger imageWidth = imageView.image.size.width;
NSInteger frameWidth = imageView.frame.size.width;
NSInteger frameHeight = imageView.frame.size.height;
NSInteger xOffSet = (frameHeight*imageWidth/imageHeight-frameWidth)/2;
CAKeyframeAnimation *animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
animation.duration = duration;
animation.repeatCount = HUGE_VALF;
animation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:160.0f],
[NSNumber numberWithFloat:160 + xOffSet],
[NSNumber numberWithFloat:160.0f],
[NSNumber numberWithFloat:160 - xOffSet],
[NSNumber numberWithFloat:160.0f], nil];
animation.removedOnCompletion = NO;
[imageView.layer addAnimation:animation forKey:nil];
}