2012-04-02 51 views
1

我展开并移动了一个标签(instructionLabel),然后将其恢复到原始大小,但将其留在新的位置。仿射转换可防止CGPoint转移

[UIView animateWithDuration:0.5 
        animations:^{ 
         CGAffineTransform scale = CGAffineTransformMakeScale(2.0, 2.0); 
         CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -70.0); // up 70 
         self.instructionsLabel.transform = CGAffineTransformConcat(scale,translate); 
        } 
        completion:^(BOOL finished) { 
         [UIView animateWithDuration:0.25 
             animations:^{ 
              CGAffineTransform scale = CGAffineTransformMakeScale(1.0,1.0); 
              CGAffineTransform translate = CGAffineTransformMakeTranslation(0,-70.0); //left in place up 70 
              self.instructionsLabel.transform = CGAffineTransformConcat(scale, translate); 
             } 
             completion:^(BOOL finished) {} 
         ]; 

后来,我明确地使用CGPointMake把标签放回原来的位置,但是(从原来的地方70分以上)仍然在平移位置。

instructionsLabel.frame = CGRectMake(384, 601, 655, 40); 
//Adding this doesn't make any difference, in or out. 

instructionsLabel.center=CGPointMake(384, 601); 

我已经休息和NSLog的验证了CGPointMake和CGRectMake语句达到...他们只是不仿射变换后的工作。有谁知道为什么? (我不想在翻译过程后立即将标签移回,但如果我不知道为什么CGPointMake例程不这样做)。

感谢您的任何建议。 -Rob

回答

1

除非Im的主要原因使用仿射变换规模弄错一个,移动等的观点是,你可以在以后设置转化为CGAffineTransformIdentity这将抵消你所应用的任何转变。我相信你的问题在于,在你应用翻译变换之前,你正在设置中心位置。视图确实移动到了这一点+任何变换适用于该视图。所以只需设置变换标识。