我正试图在不同的位置为相同的图像制作动画,如下所示:
for (int i = 0; i == 3; i++) {
UIImageView *imageToAnimate = [[UIImageView alloc] initWithFrame: imageFrameTwo];
[imageToAnimate setImage: [UIImage imageNamed: imageTwo]];
CGPoint point0 = imageTwoImage.layer.position;
CGPoint point1 = { point0.x + 10*i, point0.y - 10*i + 50};
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position.y"];
anim.fromValue = @(point0.y);
anim.toValue = @(point1.y);
anim.duration = 15.0f;
anim.repeatCount = HUGE_VALF;
anim.cumulative = NO;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
// First we update the model layer's property.
imageToAnimate.layer.position = point1;
// Now we attach the animation.
[imageToAnimate.layer addAnimation:anim forKey:@"position.y"];
[theView addSubview:imageToAnimate];
}
但没有任何反应。没有循环它运作良好。我做错了吗?
答案 0 :(得分:0)
[UIView animateWithDuration:DURATION delay:DELAY options:YOUR_UIViewAnimation animations:^(void)
这应该可以解决问题;)
答案 1 :(得分:0)
我不会详细介绍,但您可以尝试使用动画块。 0和100是原点。此外,请确保您没有使用autoLayout,您应该禁用它,或者使用自动布局约束而不是帧更改来设置动画。
[UIView animateWithDuration:0.3
delay:1
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^ {
//[yourView setFrame:CGRectMake(0,100,yourView.frame.size.width,yourView.frame.size.height )];
[yourView setFrame:CGRectMake(yourView.frame.origin.x + 100,100,yourView.frame.size.width,yourView.frame.size.height )];
}
completion:^ (BOOL finished) {
}] ;
例如,要在x轴上设置动画,您只需要在
中使用不同的x值CGRectMake ( <desired x value here>, y, ....)
动画块内的线条现在应将视图向右滑动100像素。