1

下面是我的尝试。我在导航栏中添加了一个 rightBarButtonItem。然后用下面的方法连接起来。我究竟做错了什么?当我单击按钮时,该方法被调用,因为我看到了日志。调用它时没有任何可见的事情发生。但是,如果我反复单击该按钮,图像会闪烁。

- (void)rotatedImage
{
    NSLog(@"rotatedImage");
    id <MWPhoto> assetPhoto =  [self photoAtIndex:_currentPageIndex];
    UIImageOrientation imageOrientation = assetPhoto.underlyingImage.imageOrientation;
    UIImageOrientation orientationToBe;

    if (imageOrientation == UIImageOrientationLeft) orientationToBe = UIImageOrientationDown;
    else if (imageOrientation == UIImageOrientationDown) orientationToBe = UIImageOrientationRight;
    else if (imageOrientation == UIImageOrientationRight) orientationToBe = UIImageOrientationUp;
    else orientationToBe = UIImageOrientationLeft;

    UIImage *rotatedImage = [UIImage imageWithCGImage:[assetPhoto.underlyingImage CGImage] scale: 1 orientation:orientationToBe];

    MWPhoto *r = [MWPhoto photoWithImage:rotatedImage];
    [_photos replaceObjectAtIndex:_currentPageIndex withObject:r];
    [self reloadData];  
}
4

2 回答 2

2

-(MWPhoto *) photoWithImage方法是否有可能不读取 UIImage 的方向属性?我会尝试通过将图像绘制到旋转的图像上下文中来旋转图像,然后从上下文中提取旋转的图像。查看此线程: 从旋转的 UIImageView 创建 UIImage

于 2013-12-11T05:06:13.953 回答
0

我将照片旋转功能添加到 MwphotoBrawse。它的旋转成功。可能对任何人都有帮助。我的代码是。

  id <MWPhoto> assetPhoto =  [self photoAtIndex:_currentPageIndex];
      UIImage *rotatedImage = [UIImage imageWithCGImage:[assetPhoto.underlyingImage CGImage]];
      initWithImage:rotatedImage];

        CGRect screenRect = [[UIScreen mainScreen] bounds];
        CGFloat screenWidth = screenRect.size.width;
        CGFloat screenHeight = screenRect.size.height;
        CGFloat radians = DegreesToRadians(90);

        UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0, screenWidth, screenHeight)];
        CGAffineTransform t = CGAffineTransformMakeRotation(radians);
        rotatedViewBox.transform = t;
        CGSize rotatedSize = rotatedViewBox.frame.size;

        UIGraphicsBeginImageContextWithOptions(rotatedSize, NO, [[UIScreen mainScreen] scale]);
        CGContextRef bitmap = UIGraphicsGetCurrentContext();

        CGContextTranslateCTM(bitmap, rotatedSize.width / 2, rotatedSize.height / 2);

        CGContextRotateCTM(bitmap, radians);

        CGContextScaleCTM(bitmap, 1.0, -1.0);
        CGContextDrawImage(bitmap, CGRectMake(-self.view.bounds.size.width / 2, -self.view.bounds.size.height / 2 , self.view.bounds.size.width, self.view.bounds.size.height),rotatedImage.CGImage );

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();


        MWPhoto *r = [MWPhoto photoWithImage:newImage];
        [_photos replaceObjectAtIndex:_currentPageIndex withObject:r];

        [self performLayout];
于 2016-05-04T05:13:53.090 回答