NSImageView is hoping when from the location when trying to rotate. How to stop it?

后端 未结 3 726
失恋的感觉
失恋的感觉 2021-01-27 09:54

I am rotating an NSImageView from its center which is working perfectly however when I start the animation the NSImageView hops from its location to a random location. I do not

3条回答
  •  庸人自扰
    2021-01-27 10:01

    The code looks fine to me for the animation task u require. Just move the anchorPoint line, like this:

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
        // Insert code here to initialize your application
    
        _img.layer.anchorPoint = CGPointMake(0.5f, 0.5f);   
    }
    

    EDIT: Basically, the position of a layer is specified in terms of the location of the layer's anchorPoint. When you set the position of the layer, you are then setting the location of the center of the layer in its superlayer's coordinate system. Because the position is relative to the anchorPoint of the layer, changing that anchorPoint while maintaining the same position moves the layer. So, you will have to set the anchorPoint before rendering the subview.


    Also, for infinite repeat, you can avoid writing animationDidStop method, by using this property:

    anim2.repeatCount = HUGE_VALF;
    

提交回复
热议问题