簡體   English   中英

UIImage翻轉圖像方向

[英]UIImage Flip Image Direction

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

我試圖做這樣的事情:

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

圖像不翻轉。 他們留在原地。

知道如何處理嗎?

使用此代碼對圖像進行動畫處理

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM