Tag: cabasicanimation

从viewDidLoad调用该方法时,CABasicAnimation不起作用

我有一个imageView添加到一个视图呈现为一个modalViewController,风格水平翻转。 我已经添加了下面的代码animationimageView。 – (void)animateTheImageview:(UIImageView*) imageViewToAnimate{ CABasicAnimation *fadeAnimation; fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeAnimation.duration = 1.5; fadeAnimation.repeatCount = INFINITY; fadeAnimation.autoreverses = NO; fadeAnimation.fromValue = [NSNumber numberWithFloat:1.0]; fadeAnimation.toValue = [NSNumber numberWithFloat:0.5]; fadeAnimation.removedOnCompletion = YES; fadeAnimation.fillMode = kCAFillModeForwards; [imageViewToAnimate.layer addAnimation:fadeAnimation forKey:@"animateOpacity"]; } – (void)switchOnorOff { if (onOffSwitch.on) { self.lightImage.image = [UIImage imageNamed:@"CFLGlow.jpg"]; [self animateTheImageview:self.lightImage]; } else { self.lightImage.image = […]

CABasicAnimation – 两个angular度之间的animation

我正在尝试创build一个使用CABasicAnimation的animationCALayer ,以在两个angular度之间以不连续间隔旋转的对象进行animation处理。 注意离散单词:我不是试图在两点之间创build一个连续的animation,而是我想要计算每个angular度之间的固定增量,以创build一个离散的移动感觉。 这是一张图表: 我已经考虑设置CABasicAnimation的byValue属性,但我似乎无法得到它的工作,因为你不能在一个animation中使用fromValue , ToValue ,和byValue 。 fromValue总是从零开始,所以我猜这可能会被丢弃,但是当使用当前的endAngle作为byValue和0.1的byValue (任意select,但应该用于testing)时,它仍然不会正确地animation。 任何想法如何实现这个? 这里是我正在使用的代码: anim = [CABasicAnimation animationWithKeyPath:@"currentEndAngle"]; anim.duration = 0.5f; anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; anim.toValue = [NSNumber numberWithFloat:self.endAngle]; anim.byValue = [NSNumber numberWithFloat:0.1f]; anim.repeatCount = HUGE_VALF; [anim setDelegate:self]; [self addAnimation:anim forKey:@"animKey"]; 谢谢!

在CABasicAnimation中闪烁以进行旋转

我正在试图从一个angular度旋转一个CAShapeLayer,只要按下一个button,它就会从当前angular度开始旋转。 我正在使用委托函数animationDidStop在animation结束时设置图层的变换,因为我已经注意到animation只改变了表示层的变换而不是本身的图层。 但是在animation结束时,animation完成时,由于图层在委托函数animationDidStop中更新转换之前返回到其上一个变换,animation中会出现随机闪烁。 我如何消除闪烁? @implementation ViewController – (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { [CATransaction begin]; [CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions]; self.parentLayer.transform = CATransform3DRotate(self.parentLayer.transform, DEG2RAD(60.0), 0, 0, 1); [CATransaction commit]; } – (IBAction)rotateBySixtyPressed:(id)sender { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; animation.duration = 3.0; animation.byValue = [NSNumber numberWithFloat:DEG2RAD(60.0)]; [animation setDelegate:self]; [self.parentLayer addAnimation:animation forKey:animation.keyPath]; }

在屏幕上旋转和翻译UIImageView

我怎样才能旋转和UIImageView翻译屏幕的一边,然后从另一边回来..让我说我有一个轮,我想旋转和翻译从中间,然后离开屏幕到左边,然后它从右边回到中间。 我使用下面的代码旋转和closures屏幕翻译; CABasicAnimation* rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 /* full rotation*/ * 2 * 1 ]; rotationAnimation.duration = 1; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = 1.0; rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; rotationAnimation.delegate = self; CABasicAnimation* translationAnimation; translationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; translationAnimation.toValue = [NSNumber numberWithFloat:-700]; translationAnimation.duration = 1; translationAnimation.cumulative = YES; […]

在uitableviewcell中的CABasicAnimation似乎不起作用

我试图用一个CABasicAnimation在tableview单元格内改变背景颜色的标签,它似乎并没有工作 – 单元格背景颜色保持稳定,没有animation。 此代码位于cellForRowAtIndexPath方法中 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MainCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; NSString *name = @"Hello"; UIColor *color = [UIColor colorWithRed:0.0f/255.0f green:100.0f/255.0f blue:200.0f/255.0f alpha:1.0f]; // I'm setting the label as a strong property of the cell cell.label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, cell.contentView.frame.size.height)]; cell.label.text = name; cell.label.textColor = [UIColor […]

无尽的重复滚动/animation背景在iOS?

我卡在animation2水平无限滚动的iPhone视图的图像。 背景不能有任何的差距。 如果这可以完成只有一个图像,这将是伟大的,但我似乎无法得到它。 这是我迄今为止的代码: -(void)moveImages { CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; theAnimation.duration=10; theAnimation.repeatCount=100; theAnimation.autoreverses=NO; theAnimation.fromValue=[NSNumber numberWithFloat:320]; theAnimation.toValue=[NSNumber numberWithFloat:-320]; [theImage.layer addAnimation:theAnimation forKey:@"animateLayer"]; CABasicAnimation *theAnimation2; theAnimation2=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; theAnimation2.duration=10; theAnimation2.repeatCount=100; theAnimation2.autoreverses=NO; theAnimation2.fromValue=[NSNumber numberWithFloat:640]; theAnimation2.toValue=[NSNumber numberWithFloat:-640]; [theImage2.layer addAnimation:theAnimation2 forKey:@"animateLayer2"]; }

使用UINavigationController边缘滑动时,CABasicAnimation会重置

我有以下CABasicAnimation在我的viewDidLoad运行一个UINavigationController的视图控制器: CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; animation.duration = 1; animation.additive = NO; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; animation.fromValue = [NSNumber numberWithFloat:0]; animation.toValue = [NSNumber numberWithFloat:-1*(((-windBearing+180) * M_PI) / 180)]; [compass.layer addAnimation:animation forKey:@"90rotation"]; 当我使用边缘轻扫手势慢慢地回溯,animation重置到初始状态,这是相当不和谐的。 我有我的fillMode设置和removedOnCompletion设置为NO ,我错过了什么?

CAShapeLayer在animationSwift中检测触摸

我可以检测到这样一个CAShapeLayer触摸(touchesEnded): let touchLocation : CGPoint = (touch as! UITouch).locationInView(self.view) for shape in shapes{ if CGPathContainsPoint(shape.path, nil, touchLocation, false){ print("Layer touch") } } 而且我可以像这样animation化一个CAShapeLayer的path: let newShapePath = UIBezierPath(arcCenter: toPoint, radius: 20, startAngle: CGFloat(0), endAngle: CGFloat(M_PI * 2), clockwise: true).CGPath // animate the `path` let animation = CABasicAnimation(keyPath: "path") animation.toValue = newShapePath animation.duration = CFTimeInterval(duration) animation.timingFunction = […]

获得CABasicAnimation的即时价值

当我正在执行一个游戏时,我只是一个事情的前面,我觉得这很容易,但是不知道如何解决这个问题。 我有点新的目标,你可以看到我的名誉:( 问题是,我有一个animation,这是正确的。 这里是代码: CABasicAnimation * bordgauche = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; bordgauche.fromValue = [NSNumber numberWithFloat:0.0f]; bordgauche.toValue = [NSNumber numberWithFloat:749.0f]; bordgauche.duration = t; bordgauche.repeatCount = 1; [ImageSuivante.layer addAnimation:bordgauche forKey:@"bordgauche"]; 我想获得我的形象的当前位置。 所以我使用: CALayer *currentLayer = (CALayer *)[ImageSuivante.layer presentationLayer]; currentX = [(NSNumber *)[currentLayer valueForKeyPath:@"transform.translation.x"] floatValue]; 但我不明白。 我得到一次“当前= 0.0000”,这是起始值,当我使用nslog打印它,而不是其他人。 我不知道如何一直得到我的形象currentX的即时位置。 我希望我是可以理解的。 谢谢你的帮助 :)

当模态地显示另一个VC时,CABasicAnimation会被完成

我用下面的方法暂停/恢复animation func pauseAnimation(){ var pausedTime = layer.convertTime(CACurrentMediaTime(), fromLayer: nil) layer.speed = 0.0 layer.timeOffset = pausedTime } func resumeAnimation(){ var pausedTime = layer.timeOffset layer.speed = 1.0 layer.timeOffset = 0.0 layer.beginTime = 0.0 let timeSincePause = layer.convertTime(CACurrentMediaTime(), fromLayer: nil) – pausedTime layer.beginTime = timeSincePause } 只要当前呈现ViewController,它就像魅力一样。 当我以模态方式呈现另一个视图控制器,然后将其解除时,无论本次/解散操作过程耗费了多less时间,animation都会完成。 你有什么build议,为什么会发生这种情况? 如何解决它? 我想补充说,所有其他的视图保持其状态,只有animation完成。 编辑: 我刚才发现,在这种情况下,暂停/恢复正在进行的animation也会完成。 这是我的代码,显示animation实现 import Foundation import UIKit […]