Ios 一些基本的动画图片
我正在尝试在不同的位置设置相同图像的动画,如下所示:Ios 一些基本的动画图片,ios,uiimageview,cabasicanimation,Ios,Uiimageview,Cabasicanimation,我正在尝试在不同的位置设置相同图像的动画,如下所示: for (int i = 0; i == 3; i++) { UIImageView *imageToAnimate = [[UIImageView alloc] initWithFrame: imageFrameTwo]; [imageToAnimate setImage: [UIImage imageNamed: imageTwo]]; CGPoint point0 = ima
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];
}
但什么也没发生。没有循环,它工作得很好。我做错什么了吗
[UIView animateWithDuration:DURATION delay:DELAY options:YOUR_UIViewAnimation animations:^(void)
这应该可以奏效;) 我不会详细介绍,但您可以尝试使用动画块。0和100是原点。此外,请确保未使用“自动布局”,应禁用它,或使用“自动布局”约束(而不是帧更改)设置动画
[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轴上设置动画,只需在
CGRectMake ( <desired x value here>, y, ....)
CGRectMake(,y,…)
动画块内的线条现在应该将视图向右滑动100像素。为什么不使用[UIView animateWithDuration:]?有很多。您应该首先访问www.google.com。[UIView animateWithDuration:5延迟:0.2选项:imageToAnimate动画:^{imageToAnimate.frame=CGRectMake(imageToAnimate.frame.origin.x+10,imageToAnimate.frame.origin.y-10+50,imageToAnimate.frame.size.width,imageToAnimate.frame.size.height);}完成:^(BOOL finished){NSLog(@“done”);}];喜欢这样做。如何无限化它?所以你希望它永远不会停止?永远动画?好吧,只需将它放在一个单独的方法中,然后在每次完成时从完成处理程序调用它;)。。。。这是你的问题吗?一个选项是UIViewAnimationOptionCurveLinear,但没有任何重复的选项。。。但是递归的想法应该可以做到这一点(Y)有一个选项:UIViewAnimationOptionRepeat是的,我喜欢这样)它非常有用。如何使用这些选项?像数组一样?@Pavel,如果你像我一样使用“|”字符将它们分开,你可以输入任何动画选项。还有很多其他的选项,在写了一个后用鼠标左键点击可以看到整个列表。对不起,应该是cmd+鼠标左键点击。我怎么能用这个做复杂的动画呢?就像移动x+389;?这其实很简单,扩展了我的答案。