Ios 如何向MWPhotoBrowser添加旋转照片功能?

Ios 如何向MWPhotoBrowser添加旋转照片功能?,ios,objective-c,mwphotobrowser,Ios,Objective C,Mwphotobrowser,下面是我的尝试。我在导航栏中添加了一个RightBarButtonim。然后用下面的方法连接它。我做错了什么? 当我单击按钮时,该方法被调用,因为我看到了日志。调用时不会发生任何可见的事件。但是,如果我反复单击按钮,图像会闪烁 - (void)rotatedImage { NSLog(@"rotatedImage"); id <MWPhoto> assetPhoto = [self photoAtIndex:_currentPageIndex]; UIIma

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

- (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];  
}
-(无效)旋转图像
{
NSLog(“旋转图像”);
id assetPhoto=[自拍照索引:_currentPageIndex];
UIImageOrientation imageOrientation=assetPhoto.UnderlineImage.imageOrientation;
UIImageOrientation-orientationToBe;
如果(imageOrientation==UIImageOrientationLeft)orientationToBe=UIImageOrientationDown;
否则,如果(imageOrientation==UIImageOrientationDown)orientationToBe=UIImageOrientationRight;
否则,如果(imageOrientation==UIImageOrientationRight)orientationToBe=UIImageOrientationUp;
else-orientationToBe=UIImageOrientationLeft;
UIImage*RotateImage=[UIImage imageWithCGImage:[assetPhoto.underlyingImage CGImage]比例:1方向:方向为];
MWPhoto*r=[MWPhoto photoWithImage:rotateImage];
[_photosreplaceObjectAtIndex:_currentPageIndexwith object:r];
[自重新加载数据];
}

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

我将照片旋转功能添加到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];
id assetPhoto=[self photoAtIndex:_currentPageIndex];
UIImage*RotateImage=[UIImage imageWithCGImage:[assetPhoto.underlyingImage CGImage]];
initWithImage:RotateImage];
CGRect screenRect=[[UIScreen mainScreen]边界];
CGFloat screenWidth=screenRect.size.width;
CGFloat screenHeight=screenRect.size.height;
CGFloat弧度=度弧度(90);
UIView*rotatedViewBox=[[UIView alloc]initWithFrame:CGRectMake(0,0,屏幕宽度,屏幕高度)];
CGAffineTransform t=CGAffineTransformMakeRotation(弧度);
rotatedViewBox.transform=t;
CGSize rotatedSize=rotatedViewBox.frame.size;
UIGraphicsBeginImageContextWithOptions(旋转大小,编号,[[UIScreen Main Screen]比例]);
CGContextRef位图=UIGraphicsGetCurrentContext();
CGContextTranslateCm(位图,rotatedSize.width/2,rotatedSize.height/2);
CGContextRotateCTM(位图,弧度);
CGContextScaleCTM(位图,1.0,-1.0);
CGContextDrawImage(位图,CGRectMake(-self.view.bounds.size.width/2,-self.view.bounds.size.height/2,self.view.bounds.size.width,self.view.bounds.size.height),rotateImage.CGImage);
UIImage*newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
MWPhoto*r=[MWPhoto photoWithImage:newImage];
[_photosreplaceObjectAtIndex:_currentPageIndexwith object:r];
[自我执行布局];

是否调用了此代码?如果是,会发生什么?提供更多详细信息。代码被调用,因为我看到了日志。调用时不会发生任何可见的事件。但是,如果我反复单击按钮,图像会闪烁。我也尝试使用上下文旋转图像。但它不会旋转。是否成功旋转图像?如果是,则如何旋转?如何使用此代码以及在何处使用此代码?你能正确引导吗?