UIView(内部有 UIImageView)缩放后如何重置锚点?
我想对一些包含 UIImageView 的 UIView 进行 catransform3dmakerotation ,这样它们看起来就像在旋转。它可以工作,但是在我缩放 UIView (并因此拉伸其中的图像)后,锚点是错误的(不再位于图形的中心)。
如何重置锚点?我的意思是真的重置它。因为我尝试了这个:
[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);
每次更改加速度计值时(重新缩放后几乎每 0.1 秒更新一次),图像都会旋转但不再居中,它似乎在其原点 (0,0) 上旋转,而不是(0.5,0.5),尽管它应该在 accelerometer: didAccelerate: 方法中更新。但这没有用。这是重新缩放代码:
UIView* buttView = (UIView*) [self.view viewWithTag:101];
UIImageView* butt = (UIImageView*)[self.view viewWithTag:100];
butt.frame= CGRectMake(butt.frame.origin.x, butt.frame.origin.x, newSize, newSize);
buttView.frame = butt.frame;
谢谢!
I want to do catransform3dmakerotation on some UIView that contain UIImageView so that it looks like they are rotating. It works, BUT the anchor point is wrong (no longer at the center of the graphics) after I scaled the UIView (and hence stretched the image in it).
How to reset the anchor point? I mean REALLY reset it. Because I tried this :
[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);
And every time the accelerometer value is changed, which is updating pretty much every 0.1 second after rescaling, the image is rotating but no longer centered anymore, it seems to be rotating on its origin (0,0), instead of (0.5,0.5), altho it should be updated in the accelerometer: didAccelerate: method. But it didn't work. Here is the rescaling code:
UIView* buttView = (UIView*) [self.view viewWithTag:101];
UIImageView* butt = (UIImageView*)[self.view viewWithTag:100];
butt.frame= CGRectMake(butt.frame.origin.x, butt.frame.origin.x, newSize, newSize);
buttView.frame = butt.frame;
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在更改
anchorPoint
之前,您需要记住旧框架,并在更改后重置它。像这样:Before changing the
anchorPoint
you need to remember the old frame and after changing reset it. Like this: