NSView 内容的动画旋转 [英] Animated rotation of NSView contents

查看:28
本文介绍了NSView 内容的动画旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试就地旋转 NSView (NSButton) 的内容(即从中心.我想转换 -|).这可以通过 setFrameCenterRotation: 来完成……但是,我正在尝试对此进行动画处理,并且

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];

使控件首先向右跳转,然后围绕左下角 (0,0) 旋转回到原始位置.

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

有人建议先设置anchorPoint:

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

但由于某种原因,动画取消了它并重置为 (0, 0).

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

那么,有没有人想出如何为 NSView 的就地旋转设置动画?

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

推荐答案

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

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);


}

这篇关于NSView 内容的动画旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆