2015-09-28 156 views
0

CATransform3DMakeRotation設置AnchorPoint和位置 iOS7查看位置錯誤... 但iOS8和iOS9沒有這個問題.. 爲什麼?CATransform3DMakeRotation設置錨點和位置。 iOS7查看位置錯誤


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

回答

0

這可能是由於使用了自動佈局,在iOS8上和各大他們固定它。
沒有太多的解決方案,其中一個是保持您在容器視圖內轉換的視圖。您可以在容器視圖上使用約束來定位它,並將它放在包含的視圖中(需要轉換視圖),只需將-translatesAutoresizingMaskIntoConstraints保留爲YES即可將其添加爲子視圖。
檢查馬特book

+1

兄弟你這麼酷...我的問題已解決 –