【发布时间】:2011-04-28 16:46:56
【问题描述】:
这是对上一个问题的跟进。我下面的代码通过缩放和旋转正方形来为正方形设置动画。它通过进行旋转变换并为其添加比例变换来实现这一点。这很好用。完成后,它会调用throbReset。我曾经让throbReset 只是将self's transform 设置为CGAffineTransformMakeScale,这样会取消缩放,但也会取消旋转。所以我尝试从当前的transform 开始并为其添加不缩放,但现在它什么也没做(可见)。
CGColorRef color = [[colorArray objectAtIndex:colorIndex] CGColor];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDidStopSelector:@selector(throbReset:context:)];
// [[self layer] setFillMode:kCAFillModeForwards]; // apparently not needed
CGAffineTransform xForm = CGAffineTransformMakeScale(2.0, 2.0);
xForm = CGAffineTransformRotate(xForm, M_PI / 4);
[self setTransform:xForm];
[[self layer] setBackgroundColor:color];
[UIView commitAnimations];
}
- (void)throbReset:(NSString *)animationID context:(void*)context {
NSLog(@"-%@:%s fired", [self class], _cmd);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
CGAffineTransform xForm = [self transform];
xForm = CGAffineTransformScale(xForm, 1.0, 1.0);
[self setTransform:xForm];
[UIView commitAnimations];
}
【问题讨论】:
标签: iphone animation uiview ios transform