我只是好奇为什么你不能访问 view.center.x 或 view.center.y 但你可以访问 view.center 并更改它。
我想写这段代码:
imgView_.center = scrollView_.center;
if (imgView_.frame.origin.x < 0)
imgView_.center = CGPointMake(imgView_.center.x + (imgView_.frame.size.width - self.view.frame.size.width) / 2, imgView_.center.y);
if (imgView_.frame.origin.y < 0)
imgView_.center = CGPointMake(imgView_.center.x, imgView_.center.y + (imgView_.frame.size.height - self.view.frame.size.height) / 2);
作为:
imgView_.center = scrollView_.center;
if (imgView_.frame.origin.x < 0)
imgView_.center.x = imgView_.center.x + (imgView_.frame.size.width - self.view.frame.size.width) / 2;
if (imgView_.frame.origin.y < 0)
imgView_.center.y = imgView_.center.y + (imgView_.frame.size.height - self.view.frame.size.height) / 2;
我发现第二种方式更优雅,但我无法访问 x 和 y,所以我想我会问是否有人知道 Apple 阻止它的原因是什么。