2013-12-10 26 views
1

以下是我的嘗試。我在導航欄中添加了一個rightBarButtonItem。然後用下面的方法連接它。我究竟做錯了什麼? 當我點擊按鈕時,該方法被調用,因爲我看到日誌。當它被調用時沒有可見的事情發生。如果我反覆點擊按鈕,圖像會閃爍。如何將旋轉照片功能添加到MWPhotoBrowser?

- (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]; 
} 
+0

這段代碼是否被調用?如果是這樣,會發生什麼?提供更多細節。 – rmaddy

+0

代碼被調用,因爲我看到日誌。當它被調用時沒有可見的事情發生。如果我反覆點擊按鈕,圖像會閃爍。 – user299648

+0

我也嘗試使用context.but旋轉圖像,但它不rotate.have旋轉圖像succesfuly?如果是,那麼如何? – ABJ

回答

2

有沒有可能-(MWPhoto *) photoWithImage方法不讀取UIImage的方向屬性?我會嘗試旋轉圖像,將其繪製到旋轉的圖像上下文中,然後從上下文中提取旋轉後的圖像。檢查出這個線程: Creating a UIImage from a rotated UIImageView

0

我添加照片旋轉功能到MwphotoBrawse.Its旋轉成功。可以幫助任何。我的代碼是。

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];