使图片自动移动的方法

来源:互联网 发布:帝国cms 整站迁移 编辑:程序博客网 时间:2024/06/05 06:43

使图片自动移动的方法

by lesvio

- (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];}



gif不会动!!!!唉!!!!!!!!
0 0
原创粉丝点击