IOS 的動畫放大與縮小,并非按照找它的中心點放大和縮小,而是左上角 。我分析了下原來是Autolayout 與View Transforms的沖突造成的。
- (void) addSubviewWithZoomInAnimation:(UIView*)view duration:(float)secs option:(UIViewAnimationOptions)option{// first reduce the view to 1/100th of its original dimensionCGAffineTransform trans = CGAffineTransformScale(view.transform, 0.01, 0.01);view.transform = trans; // do it instantly, no animation[self addSubview:view];// now return the view to normal dimension, animating this tranformation[UIView animateWithDuration:secs delay:0.0 options:optionanimations:^{view.transform = CGAffineTransformScale(view.transform, 100.0, 100.0);}completion:nil]; }- (void) removeWithZoomOutAnimation:(float)secs option:(UIViewAnimationOptions)option{[UIView animateWithDuration:secs delay:0.0 options:optionanimations:^{self.transform = CGAffineTransformScale(self.transform, 0.01, 0.01);}completion:^(BOOL finished) { [self removeFromSuperview]; }];}
解決方案:
Disable auto layout:
self.imageView.translatesAutoresizingMaskIntoConstraints = YES;
【1】
http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used/14105757#14105757
新聞熱點
疑難解答