2013-11-04 4 views
0

대체 이미지가있는 UIImageView의 이미지를 설정하려고합니다. [imageView setImage : image] 할 수 있다는 것을 알고 있습니다. 그러나 이미지를 변경할 때 디졸브 효과 (애니메이션)를 추가 할 수 있습니까? 당신은 CAAnimation를 사용하여이를 달성 할 수iOS에서 애니메이션으로 UIImage를 설정했습니다.

답변

2

이를 위해 UIView의 transitionWithView 방법을 사용할 수 있습니다.

샘플 코드는 :

UIImage * newImage= [UIImage imageNamed:@"newImg.png"]; 
[UIView transitionWithView:self.view 
       duration:3.0f 
       options:UIViewAnimationOptionTransitionCrossDissolve 
      animations:^{ 
       yourImageView.image = newImage; 
      } completion:nil]; 
1

당신이보고 herehere 몇 가지 편리한 튜토리얼뿐만 아니라 클래스 참조를 가지고

kCATransitionFade라고 찾고있는 효과를 전환.

3

나는이 이전을 완료하고 여기 다르죠 코드는 위에서 설명한 문제에 대해 잘 작동하는 데 도움이 코드의 조각이다.

-(void)changeImage 
{ 
     myImageView.animationImages=[NSArray arrayWithArray:self.yourImageArray]; 
     myImageView.animationDuration=10.0; 
     myImageView.animationRepeatCount=0; 
     [myImageView startAnimating]; 
     myImageView.transform = CGAffineTransformMakeRotation(M_PI/2); 
     [self.view addSubview:myImageView]; 
     //The timers time interval is the imageViews animation duration devided by the  number of images in the animationImages array. 20/5 = 4 
     NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 
               target:self 
               selector:@selector(onTimer) 
               userInfo:nil 
               repeats:YES]; 

     [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; 
     [timer fire]; 

} 

// 이미지를 페이드 인하 고 페이드 아웃합니다.

-(void)onTimer{ 
     [UIView animateWithDuration:2.0 animations:^{ 
      myImageView.alpha = 0.0; 
     }]; 
     [UIView animateWithDuration:0.5 animations:^{ 
      myImageView.alpha = 1.0; 
     }]; 
    } 

당신은 십자가이 UIViewAnimationOptionTransitionCrossDissolve을 사용할 수 있습니다 용해합니다. 호프가 도움이 될 것이라면, 자유롭게 물어보십시오.

+0

답장을 보내 주셔서 감사합니다.하지만 제가하려는 일을 조금이라도 끝내십시오. 그것은 미래에 다른 어떤 것에 매우 유용 할 것입니다. – hook38

+0

당신은 환영합니다. 귀하의 문제가 아직 해결되지 않은 경우 귀하의 요구 사항을 설명해 주시면 제 답변을 수정할 것입니다. – Shivaay

관련 문제