【发布时间】:2012-07-19 10:51:49
【问题描述】:
我正在我的项目中使用 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);
}
请找到附件图片供您参考。
【问题讨论】:
-
它的缩放,但图像像给定的参考图像一样拉伸。
标签: ios5 uiimageview quartz-2d image-rotation zooming