CATransform3DMakeRotation 设置锚点和位置。 iOS7 查看位置错误
CATransform3DMakeRotation Setting AnchorPoint and position. iOS7 View position mistake
CATransform3DMakeRotation 设置锚点和位置
iOS7 查看位置错误...
但是 iOS8 和 iOS9 没有这个问题..
为什么?
-(void)viewDidAppear:(BOOL)animated
{
[self setAnchorPoint:CGPointMake(0.5, 1) forView:self.chieldImageView];
}
-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
{
CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x,
view.bounds.size.height * anchorPoint.y);
CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x,
view.bounds.size.height * view.layer.anchorPoint.y);
newPoint = CGPointApplyAffineTransform(newPoint, view.transform);
oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);
CGPoint position = view.layer.position;
position.x -= oldPoint.x;
position.x += newPoint.x;
position.y -= oldPoint.y;
position.y += newPoint.y;
view.layer.position = position;
view.layer.anchorPoint = anchorPoint;
}
这可能是由于使用了自动布局,在 iOS8 上他们修复了它。
没有那么多解决方案,一种是将要转换的视图保留在容器视图中。您在容器视图上使用约束来定位它,并在包含的(需要转换的视图)中通过将 -translatesAutoresizingMaskIntoConstraints
保持为 YES 将其添加为子视图。
查看 Matt book.
CATransform3DMakeRotation 设置锚点和位置 iOS7 查看位置错误... 但是 iOS8 和 iOS9 没有这个问题.. 为什么?
-(void)viewDidAppear:(BOOL)animated
{
[self setAnchorPoint:CGPointMake(0.5, 1) forView:self.chieldImageView];
}
-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view
{
CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x,
view.bounds.size.height * anchorPoint.y);
CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x,
view.bounds.size.height * view.layer.anchorPoint.y);
newPoint = CGPointApplyAffineTransform(newPoint, view.transform);
oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform);
CGPoint position = view.layer.position;
position.x -= oldPoint.x;
position.x += newPoint.x;
position.y -= oldPoint.y;
position.y += newPoint.y;
view.layer.position = position;
view.layer.anchorPoint = anchorPoint;
}
这可能是由于使用了自动布局,在 iOS8 上他们修复了它。
没有那么多解决方案,一种是将要转换的视图保留在容器视图中。您在容器视图上使用约束来定位它,并在包含的(需要转换的视图)中通过将 -translatesAutoresizingMaskIntoConstraints
保持为 YES 将其添加为子视图。
查看 Matt book.