次のタスクがあります。ボタンをクリックすると、画像を90度回転させる必要があります。
私のコードは次のとおりです。
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *vector;
@end
=========
@interface ViewController ()
@end
@implementation ViewController
@synthesize vector;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)rotateOn:(id)sender {
[self rotateImage:self.vector duration:2
curve:UIViewAnimationCurveEaseIn degrees:M_PI/2];
}
- (void)rotateImage:(UIImageView *)image duration:(NSTimeInterval)duration
curve:(int)curve degrees:(CGFloat)degrees
{
// Setup the animation
[UIView beginAnimations:NULL context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
[image.layer setAnchorPoint:CGPointMake(0.5,0.5)];
CGAffineTransform transform =
CGAffineTransformMakeRotation(degrees);
image.transform = transform;
[UIView commitAnimations];
}
ボタンをクリックする前にこれを持っていますこれ
をクリックした後
画像が 90 度回転することがわかります。しかし、それは開始の中心点から下に移動しました。また、もう一度ボタンをクリックしても何も起こりません。