2
votes

I'm having a horrible time trying recreate a simple iOS UIView animation in Cocoa. It's just an imageview rotating 90 degrees.

Here's the iOS implementation:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:containerView.bounds];
imageView.image = myImage;
imageView.contentMode = UIViewContentModeScaleAspectFit;
[containerView addSubView:imageView];

[UIView animateWithDuration:0.5
                 animations:^{
                         imageView.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
                         imageView.frame = containerView.bounds                             
              } completion:^(BOOL finished) {
}];

Here's the Cocoa version that doesn't work:

[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){             
    context.duration = 0.5;
    [imageView.animator setFrameCenterRotation:90];
    [imageView.animator setFrame: containerView.bounds];
} completionHandler:^{
}];

The main problem is that the rotation doesn't rotate over time, it just slams to 90 degrees, but also has an odd translation that does move the duration.

I guess I could do it with Core Animation, but I'm afraid that would open up another can of worms...especially for something so simple. As you can see, I'm way more experienced in iOS than Cocoa.

Thanks for the help.

1

1 Answers

0
votes

I know I am a little late to answer the question however, for the sake of other devs:

Here is the project that rotates the image from center.

github project link

stackOver flow link of solution