Aks*_*hta 2 gesture imageview ios
我们如何在图像视图中旋转图像并在图像上应用手势,并将该图像以与图像相同的状态保存到服务器
- (IBAction)imageMove:(id)sender {
    static int numRot = 0;
    myimage.transform = CGAffineTransformMakeRotation(M_PI_2 * numRot);
    ++numRot;
}
从这段代码我能够将我的图像视图旋转90度
用这个:-
@interface UIImage (RotationMethods)
- (UIImage *)rotateImageByDegree:(CGFloat)degrees;
@end
@implementation UIImage (RotationMethods)
static CGFloat getRadianFromDegree(CGFloat degrees) 
{返回度*M_PI/180;};
- (UIImage *) rotateImageByDegree:(CGFloat)degrees 
{   
    UIView *rotatedImageView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.size.width, self.size.height)];
    CGAffineTransform t = CGAffineTransformMakeRotation(getRadianFromDegree(degrees));
    rotatedImageView.transform = t;
    CGSize rotatedSize = rotatedImageView.frame.size;
    UIGraphicsBeginImageContext(rotatedSize);
    CGContextRef bitmap = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
    CGContextRotateCTM(bitmap, getRadianFromDegree(degrees));
    CGContextScaleCTM(bitmap, 1.0, -1.0);
    CGContextDrawImage(bitmap, CGRectMake(-self.size.width / 2, -self.size.height / 2, self.size.width, self.size.height), [self CGImage]);
    UIImage *rotatedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return rotatedImage;
}
@end
| 归档时间: | 
 | 
| 查看次数: | 583 次 | 
| 最近记录: |