2014-02-12 65 views
0

對於某個UIImageView animationImages,我希望創建2個數組 - 每個方向一個。 我有可以加載到其中一個方向的png文件,我希望翻轉每個圖像並將其添加到第二個方向數組。UIImage翻轉圖像方向

我試圖做這樣的事情:

_movingLeftImages = [NSMutableArray array]; 
    _movingRightImages = [NSMutableArray array]; 
    int imagesCounter = 0; 
    while (imagesCounter <= 8) 
    { 
     NSString* imageName = [NSString stringWithFormat:@"movingImg-%i", imagesCounter]; 

     UIImage* moveLeftImage = [UIImage imageNamed:imageName]; 
     [_movingLeftImages addObject:moveLeftImage]; 

     UIImage* moveRightImage = [UIImage imageWithCGImage:moveLeftImage.CGImage scale:moveLeftImage.scale orientation:UIImageOrientationUpMirrored]; 
     [_movingRightImages addObject:moveRightImage]; 

     imagesCounter++; 
    } 

在相關事件中,我加載的UIImageView animationImages有關陣列;像這樣:

if (/*should move LEFT event*/) 
    { 
     movingImageView.animationImages = [NSArray arrayWithArray:_movingLeftImages]; 
    } 
    if (/*should move RIGHT event*/) 
    { 
     movingImageView.animationImages = [NSArray arrayWithArray:_movingRightImages]; 
    } 

圖像不翻轉。他們保持在哪裏。

任何想法如何處理?

+0

你確定你使用了正確的方向?也許你可以上傳你想要實現的圖像。 – Gad

+0

使用QuartzCore提供給您的視圖的.layer屬性的.transformation屬性來簡單地翻轉uiimageview而不是圖像 –

+0

@A'saDickens,我該如何做翻轉?我不熟悉這個功能......我應該使用哪個函數來實現這種鏡像? –

回答

0

使用此代碼爲動畫圖像

UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200,200)]; 

    NSArray *imageNames = @[@"bird1.png", @"bird2.png"]; 
    animTime =.0; 
[animatedImageView setAnimationImages:imageNames] ; 
animatedImageView.animationDuration = animTime; 
animatedImageView.animationRepeatCount = 1; 
[self.view addSubview: animatedImageView]; 
[animatedImageView startAnimating];