如何解决ios动画中autolayout与viewtransforms的冲突
发布网友
发布时间:2022-04-19 12:56
我来回答
共1个回答
热心网友
时间:2022-04-21 18:02
<p class="p1">IOS 的动画放大与缩小,并非按照找它的中心点放大和缩小,而是左上角 。我分析了下原来是Autolayout 与View Transforms的冲突造成的。
- (void) addSubviewWithZoomInAnimation:(UIView*)view ration:(float)secs option:(UIViewAnimationOptions)option
{
// first rece the view to 1/100th of its original dimension
CGAffineTransform 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:option
animations:^{
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:option
animations:^{
self.transform = CGAffineTransformScale(self.transform, 0.01, 0.01);
}
completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
解决方案:
Disable auto layout:
self.imageView.translatesAutoresizingMaskIntoConstraints = YES;