如何以编程方式在iPhone中将图像旋转90度?
答案 0 :(得分:71)
//create rect
UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_image.png"]];
//set point of rotation
myImageView.center = CGPointMake(100.0, 100.0);
//rotate rect
myImageView.transform = CGAffineTransformMakeRotation(M_PI_2); //rotation in radians
答案 1 :(得分:6)
看到这个:
Rotate image in Quartz? Image is upside down! (iPhone)
myImage.center = CGPointMake(0, 0);
myImage.transform = CGAffineTransformMakeRotation([degreesToRadians:imageRotationFix]);
答案 2 :(得分:4)
此代码将旋转按钮..
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(100, 100, 200, 44)];
btn.transform=CGAffineTransformMakeRotation(M_PI / -4);
[btn setTitle:@"RakeshBhatt" forState:UIControlStateNormal];
[self.view addSubview:btn];
你可以旋转imageview。