我有一个应该启动动画的功能。三角形是用“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));
}
}