我有一个应该启动动画的功能。三角形设计为“drawrect”,我在控制器中有一个按钮,当按下它时,它会调用“startTriangleAnimation”。
问题是方法“startTriagnleAnimation”没有添加动画。我确信程序进入此方法是因为它打印了NSLOG。
谁知道怎么办?- (void)startTriangleAnimation
{
[self setNeedsDisplay];
if (_leftFoot) {
NSLog(@"LEFT FOOT ANIMATION STARTING");
[UIView animateWithDuration:15
delay:0
options: UIViewAnimationOptionCurveLinear
animations:^{
self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-FIRST_ROTATION));
} completion:^(BOOL finished) {
[UIView animateWithDuration:15
delay:0.5
options: UIViewAnimationOptionCurveLinear
animations:^{
self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(-SECOND_ROTATION));
} completion:^(BOOL finished) {
[UIView animateWithDuration:15
delay:0.5
options: UIViewAnimationOptionCurveLinear
animations:^{
self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(-THIRD_ROTATION));
}completion:^(BOOL finished) {
[UIView animateWithDuration:15
animations:^{
self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(-FOURTH_ROTATION));
}];
}];
}];
}];
} else {
NSLog(@"RIGHT FOOT ANIMATION STARTING");
[UIView animateWithDuration:15
delay:0
options: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState
animations:^{
NSLog(@"animating");
self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(FIRST_ROTATION));
} completion:^(BOOL finished) {
[UIView animateWithDuration:15
delay:0.5
options: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(SECOND_ROTATION));
} completion:^(BOOL finished) {
[UIView animateWithDuration:15
delay:0.5
options: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(THIRD_ROTATION));
}completion:^(BOOL finished) {
[UIView animateWithDuration:15
animations:^{
self.transform = CGAffineTransformRotate(self.transform, DEGREES_TO_RADIANS(FOURTH_ROTATION));
}];
}];
}];
}];
}
}
- (void)drawRect:(CGRect)rect
{
CGFloat x = self.bounds.size.height;
CGFloat y = self.bounds.size.width;
[[UIColor redColor] setStroke];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(x/2, y - 20)];
[path addLineToPoint:CGPointMake(x/2 - 10, y)];
[path addLineToPoint:CGPointMake(x/2 + 10, y)];
[path closePath];
[path fill];
//[path stroke];
if (_leftFoot) {
self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(10));
} else {
self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-10));
}
}
答案 0 :(得分:0)
一种可能的解释是您在FIRST_ROTATION等变量中有意外值。
另一个是你在drawRect中旋转。在我看来,这会产生意想不到的后果。如果您希望“基本三角形”不直,只需计算路径的相应点并立即绘制。