我移动一个带动画的按钮,如果我在UIVIewController中使用它完全正常工作,如果我尝试使用这个动画继承UIView我看不到它,按钮出现在终点但是我不知道看它动了。 错误在哪里?
这是我的代码:
- (void) moveButton:(UIButton *)button fromPoint:(CGPoint)startPoint toPoint:(CGPoint)endPoint {
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath, NULL, startPoint.x, startPoint.y);
NSMutableArray *timings = [NSMutableArray array];
NSMutableArray *keytimes = [NSMutableArray array];
// Start
[timings addObject:[self getTiming:kCAMediaTimingFunctionEaseIn]];
[keytimes addObject:[NSNumber numberWithFloat:0.0]];
// Bounce
[timings addObject:[self getTiming:kCAMediaTimingFunctionEaseIn]];
[keytimes addObject:[NSNumber numberWithFloat:1.0]];
CAKeyframeAnimation * animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.duration = 2;
animation.path = thePath;
animation.timingFunctions = timings;
animation.keyTimes = keytimes;
[[button layer] addAnimation:animation forKey:nil];
[[button layer] setPosition:CGPointMake(endPoint.x,endPoint.y)];
}