プロジェクトで UIImageview を使用してズームと回転を実装していますが、画像を回転させた後にズームインとズームアウトの問題に直面しています。
これが私のコードです:
.h ファイル内
@interface ViewController : UIViewController{
float degrees;
float height;
float width;
float moveLeft;
float moveRight;
}
@property(nonatomic,retain)UIImageView *imageView;
-(IBAction)rotationLeft:(id)sender;
-(IBAction)rotationRight:(id)sender;
-(IBAction)zoomIn:(id)sender;
-(IBAction)zoomOut:(id)sender;
-(IBAction)moveLeft:(id)sender;
-(IBAction)moveRight:(id)sender;
.m ファイルで
- (void)viewDidLoad
{
[super viewDidLoad];
height=50;
width=50;
degrees=20;
moveLeft=20;
moveRight=20;
imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.png"]];
imageView.frame=CGRectMake(100, 100,width, height);
[self.view addSubview:imageView];
// Do any additional setup after loading the view, typically from a nib.
}
-(IBAction)rotationLeft:(id)sender{
//the value in degrees
imageView.transform = CGAffineTransformMakeRotation(degrees*M_PI/180);
degrees=degrees+25;
}
-(IBAction)rotationRight:(id)sender{
//the value in degrees
degrees=degrees-25;
imageView.transform = CGAffineTransformMakeRotation(degrees*M_PI/180);
}
-(IBAction)zoomIn:(id)sender{
height=height-15;
width=width-15;
imageView.frame=CGRectMake(100, 100,width, height);
}
-(IBAction)zoomOut:(id)sender{
height=height+15;
width=width+15;
imageView.frame=CGRectMake(100, 100,width, height);
}
添付の画像を参考にしてください。