开发者

question about CGAffineTransformTranslate

开发者 https://www.devze.com 2022-12-26 17:53 出处:网络
CGRect rect1 = backgroundImageView.frame; NSLog(@\"%f,%f,%f,%f\",rect1.origin.x,rect1.o开发者_如何学Gorigin.y,
CGRect rect1 = backgroundImageView.frame;
NSLog(@"%f,%f,%f,%f",rect1.origin.x,rect1.o开发者_如何学Gorigin.y,
                     rect1.size.width,rect1.size.height);

angle = -90.0;
moveX = 0;
moveY = 0.0;

CGFloat degreesToRadians = M_PI * angle / 180.0;
CGAffineTransform landscapeTransform =
      CGAffineTransformMakeRotation(degreesToRadians);
landscapeTransform =
      CGAffineTransformTranslate(landscapeTransform, moveX, moveY);
[backgroundImageView setTransform:landscapeTransform]; 

rect1 = backgroundImageView.frame;
NSLog(@"%f,%f,%f,%f",rect1.origin.x,rect1.origin.y,
                     rect1.size.width,rect1.size.height);

the debug message output:

0.000000,0.000000,320.000000,480.000000
-80.000000,80.000000,480.000000,320.000000

why does the (x,y) changes to (-80,80)?


When you set the transform, the backgroundImageView.center does not change. If the parent view has already rotated, yout can do something like this after applying the transform.

backgroundImageView.center = backgroundImageView.superview.center;

Either way, for your purposes you should adjust the center and not translate the transform.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号