在CALayer中实现缩放

发布于 2024-12-21 22:36:46 字数 733 浏览 1 评论 0原文

我正在尝试在分层托管 NSVIew 中的 CALayer 上实现缩放。带有图层的 NSView(图层大小:1024x768)位于 NSScrollView 内部。我实现缩放的方法如下:

- (IBAction)zoomOut:(NSButton *)sender {
CALayer *layer = self.editorView.layer;
CGRect frame = layer.frame;
frame.size.width = frame.size.width / 2;
frame.size.height = frame.size.height / 2; 
layer.frame = frame;
}

- (IBAction)zoomIn:(NSButton *)sender {
   CALayer *layer = self.editorView.layer;
   CGRect frame = layer.frame;
  frame.size.width = frame.size.width * 2;
  frame.size.height = frame.size.height * 2; 
  layer.frame = frame;
}

单击 NSView 中的放大或缩小按钮后,问题是每当我滚动 NSView 时(请记住,我将 NSView 放在 NSScrollView 中,并且 NSView 是大于 NSScrollView),CALayer 会自动调整为原始大小(即 1024x768)。我无法弄清楚原因。 任何形式的帮助将不胜感激。

I'm trying to implement zoom on a CALayer in a layered-hosting NSVIew. The NSView with the layer (size of the layer: 1024x768) is inside an NSScrollView. What I did to implement the zoom is the following

- (IBAction)zoomOut:(NSButton *)sender {
CALayer *layer = self.editorView.layer;
CGRect frame = layer.frame;
frame.size.width = frame.size.width / 2;
frame.size.height = frame.size.height / 2; 
layer.frame = frame;
}

- (IBAction)zoomIn:(NSButton *)sender {
   CALayer *layer = self.editorView.layer;
   CGRect frame = layer.frame;
  frame.size.width = frame.size.width * 2;
  frame.size.height = frame.size.height * 2; 
  layer.frame = frame;
}

After clicking on the button for zooming in or zooming out in the NSView, the problem is that whenever i scroll the NSView (remember that I put the NSView inside an NSScrollView, and that the NSView is bigger than the NSScrollView), the CALayer resizes automatically to the original size (i.e. 1024x768). I cannot figure out the reason.
Any kind of help would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2024-12-28 22:36:46

+ (CALayer *)layer 别名后备存储(我称之为根层)随视图调整大小,没有办法阻止这种情况。

+ (CALayer *)layer alias backing store (I call it root layer) resizes with the view, there is no way to prevent this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文