NSView 内容的动画旋转

发布于 2024-12-02 11:31:40 字数 502 浏览 0 评论 0原文

我正在尝试就地旋转 NSView (NSButton) 的内容(即从中心旋转。我想将 - 转换为<代码>|)。这可以通过 setFrameCenterRotation: 来完成...但是,我正在尝试为其设置动画,并

[[myview animator] setFrameCenterRotation: 90];

导致控件首先跳到右侧,然后绕左下角 (0,0) 旋转回到原来的位置。

有些人建议首先设置 anchorPoint

[[myview layer] setAnchorPoint: NSMakePoint(0.5, 0.5)];

但由于某种原因,动画取消了此设置,并将其重置为 (0, 0)。

那么,有人知道如何为 NSView 的就地旋转设置动画吗?

I'm trying to rotate the contents of an NSView (NSButton) in-place (I.e. from the center. I want to convert - into |). This can be done with setFrameCenterRotation: … However, I'm trying to animate this, and

[[myview animator] setFrameCenterRotation: 90];

causes the control to first jump to the right, and then rotate around the bottom-left corner (0,0) back to the original location.

Some people have suggested first setting the anchorPoint:

[[myview layer] setAnchorPoint: NSMakePoint(0.5, 0.5)];

but for some reason the animation cancels this out and it gets reset to (0, 0).

So, has anybody figured out how to animate an in-place rotation of an NSView?

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

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

发布评论

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

评论(1

深陷 2024-12-09 11:31:40

如果您从界面生成器添加控件并使用其 IBOutlet 旋转它,则不会发生这种情况。您不必使用“setAnchorPoint:”方法; “setFrameCenterRotation:”方法本身就可以工作。然而,当我尝试旋转 NSCell 中作为子视图的 NSButton 时,同样的事情发生在我身上。解决方案是将 NSView 作为 controlView 中的子视图(请参阅下面的 NSCell 子类)和 NSButton 我需要旋转作为该新 NSView 的子视图。

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView{

    if (![btnCheckBackView superview]) {
        //btnCheckBackView is my NSView holding the NSButton "btnCheck"
        [btnCheckBackView setFrame:NSRectFromCGRect(CGRectMake(9, cellFrame.origin.y+8, 28, 28))];
        [controlView addSubview:btnCheckBackView];
        if (![btnCheck superview]) {
            [btnCheck setFrame:NSRectFromCGRect(CGRectMake(0, 0, 28, 28))];
            [btnCheckBackView addSubview:btnCheck];

        }
    }




//    NSLog(@"drawWithFrame"); 
//    NSLog(@"Rect %d,%d,%d,%d",(int)cellFrame.origin.x,(int)cellFrame.origin.y,(int)cellFrame.size.width,(int)cellFrame.size.height);
//    NSLog(@"controlView %d,%d,%d,%d",(int)controlView.frame.origin.x,(int)controlView.frame.origin.y,(int)controlView.frame.size.width,(int)controlView.frame.size.height);


}

This doesn't happen if you add the control from interface builder and rotate it using its IBOutlet. You will not have to use "setAnchorPoint:" method; "setFrameCenterRotation:" method itself will work. However the same thing happened to me when I tried to rotate a NSButton I have in my NSCell as a subview. The solution was to have an NSView as a subview in the controlView (refer the NSCell subclass below) and NSButton I require rotation as a subview of that new NSView.

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView{

    if (![btnCheckBackView superview]) {
        //btnCheckBackView is my NSView holding the NSButton "btnCheck"
        [btnCheckBackView setFrame:NSRectFromCGRect(CGRectMake(9, cellFrame.origin.y+8, 28, 28))];
        [controlView addSubview:btnCheckBackView];
        if (![btnCheck superview]) {
            [btnCheck setFrame:NSRectFromCGRect(CGRectMake(0, 0, 28, 28))];
            [btnCheckBackView addSubview:btnCheck];

        }
    }




//    NSLog(@"drawWithFrame"); 
//    NSLog(@"Rect %d,%d,%d,%d",(int)cellFrame.origin.x,(int)cellFrame.origin.y,(int)cellFrame.size.width,(int)cellFrame.size.height);
//    NSLog(@"controlView %d,%d,%d,%d",(int)controlView.frame.origin.x,(int)controlView.frame.origin.y,(int)controlView.frame.size.width,(int)controlView.frame.size.height);


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