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

后端 未结 3 686
失恋的感觉
失恋的感觉 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:28

    You need to set the position of the layer, on the Image View. Add this in the buttonPressed method:

    //Position of the imgView
    CGRect frame = _img.layer.frame;
    
    float xCoord = frame.origin.x + frame.size.width;
    float yCoord = frame.origin.y + frame.size.height;
    
    CGPoint myPoint = CGPointMake(xCoord, yCoord);
    _img.layer.position = myPoint;
    
    [self startRefreshAnimation]
    

    that way, you can move the imageView around in the .xib, and the animation will take place the correct spot.

    Edit: The solution by @Nishant is so much prettier..

提交回复
热议问题