iphone - 在不撤消旋转变换的情况下无法撤消缩放变换

标签 iphone animation uiview ios transform

这是对上一个问题的跟进。我下面的代码通过缩放和旋转它来动画一个正方形。它通过进行旋转变换并向其添加缩放变换来实现。那很好用。完成后,它会调用 throbReset。我曾经让 throbReset 只是将 self's transform 设置为 CGAffineTransformMakeScale,这会取消缩放,但也会取消旋转。所以我尝试从当前的 transform 开始并向其添加 unscale,但现在它什么也没做(可见)。


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];
}

最佳答案

你只是缩放到相同的大小,因为你基本上是说采用当前变换并在 X 上按 1:1 缩放,在 Y 上按 1:1 缩放。你可能想在你的中执行 0.5,0.5 而不是 1.0,1.0第二种方法。

CGAffineTransform xForm = [self transform];
xForm = CGAffineTransformScale(xForm,0.5, 0.5);

请记住,当您以相反的顺序添加旋转时,先旋转再缩放。如果您涉及翻译,这将更为重要,但在这种情况下,两种方式都可能有效。

关于iphone - 在不撤消旋转变换的情况下无法撤消缩放变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3989178/

相关文章:

ios - 如何将 UICollectionView 作为 subview 添加到 UIView?

ios - 在 UIView.animateWithDuration() 期间为手势识别器启用用户交互

iPhone 无法使用 MPMoviePlayerController 将视频旋转到横向模式

iphone - 在 PC 上使用 iPhone 摄像头作为网络摄像头

iphone - 检测 iPhone/iPod Touch 配件

html - 无法在 css 动画中将文本保留在屏幕上

iphone - 在头文件中使用变量和常量定义进行本地化

c# - 在 WPF 中启动 XAML 动画

javascript - D3 Javascript - 这些行不会移动

ios - 为可调整大小的 UIView 设置最小和最大宽度和高度