如何使NSView尊重其CALayer的位置/边界

时间:2019-06-27 21:58:47

标签: cocoa calayer nsview appkit

我想更改NSView的大小/位置而不影响其图层变换。

任何线索为何self.frame 响应其图层的大小/位置更改?

// This exists in a NSView category
- (void)setLayerFrame:(CGRect)frame
{
  [CATransaction begin];
  [CATransaction setDisableActions:YES];
    self.layer.bounds = (CGRect){CGPointZero, frame.size};
    self.layer.position = frame.origin;
  [CATransaction commit];

  // Always logs "{{0, 0}, {0, 0}}"
  NSLog(@"frame => %@", NSStringFromRect(self.frame));
}

0 个答案:

没有答案