在CALayer中实现缩放
我正在尝试在分层托管 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
+ (CALayer *)layer
别名后备存储(我称之为根层)随视图调整大小,没有办法阻止这种情况。+ (CALayer *)layer
alias backing store (I call it root layer) resizes with the view, there is no way to prevent this.