2013-08-28 7 views
3

반전 애니메이션의 절반으로 UIImageView 이미지를 어떻게 바꿀 수 있습니까? 내 코드가 UIImageView를 뒤집어 성공적으로 이미지를 변경하는 것처럼 보이지만 순간적으로 바뀌고 있습니다. 내가 원하는 것은 180 플립이 90도 플립에 도달하면 이미지를 변경하는 것입니다.UIImageView 이미지를 반전 애니메이션의 절반으로 변경하십시오.

뷰에있는 UIImageView 만들기 : 여기 내 코드는 탭에

UIImage *image = [UIImage imageNamed:@"fb1.jpg"]; 
    imageView = [[UIImageView alloc] initWithImage:image]; 
    vw = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)]; 
    vw.layer.cornerRadius = vw.frame.size.width/2; 
    imageView.frame = CGRectMake(20, 20, 80, 80); 
    imageView.layer.cornerRadius = imageView.frame.size.width/2; 
    imageView.layer.masksToBounds = YES; 
    imageView.layer.borderColor = [[UIColor blackColor] CGColor]; 
    imageView.layer.borderWidth = 1.0; 
    [self.view addSubview: imageView]; 
    //[self.view addSubview:vw]; 
    [imageView setUserInteractionEnabled:YES]; 
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(taptap:)]; 
    [imageView addGestureRecognizer:tap]; 

애니메이션의 UIImageView : 또한

[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut 
        animations:^(void) { 
         imageView.transform = CGAffineTransformMakeScale(-1, 1); 
         [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionTransitionCrossDissolve 
              animations:^(void) { 
               imageView.image = [UIImage imageNamed:@"fb2.jpg"]; 
              } completion:^(BOOL finished) { 

              }]; 
        } 
        completion:^(BOOL finished) { 
        }]; 

, 나는 특정있는 UIImageView에 탭 제스처에이 애니메이션을하고있는 중이 야.

+0

는 http://stackoverflow.com/questions/1194752/how-can-i-flip-a-uiimageview 내가 그 링크를 따라하려고 – iOS

+0

대답은 내 둥근있는 UIImageView 광장을합니다. –

답변

19

이 애니메이션의 경우 클래스 메서드 + (void)transitionWithView:duration:options:animations:completion:을 쉽게 사용할 수 있습니다. 애니메이션이 같은

사용 코드 :

[UIView transitionWithView:imageView 
        duration:0.4 
        options:UIViewAnimationOptionTransitionFlipFromRight 
       animations:^{ 
        // Set the new image 
        // Since its done in animation block, the change will be animated 
        imageView.image = newImage; 
       } completion:^(BOOL finished) { 
        // Do whatever when the animation is finished 
       }]; 

다음 옵션 중 하나와 UIViewAnimationOptionTransitionFlipFromRight를 대체하여 플립의 방향을 설정할 수 있습니다 당신이 경우, 두 단계의 애니메이션을 시도

UIViewAnimationOptionTransitionFlipFromLeft 
UIViewAnimationOptionTransitionFlipFromRight 
UIViewAnimationOptionTransitionFlipFromTop 
UIViewAnimationOptionTransitionFlipFromBottom 
+0

고마워요.하지만 고맙겠습니다. 애니메이션이 필요합니다. 뒤집기 동전의 반투명 인 이미지를 바꾸고 싶을뿐입니다. –

+0

나는 당신이 성취하려고하는 것을 얻지 못한다. 180 ° 플립 애니메이션 (종이의 한면에서 다른면으로) 또는 전체 360 ° 플립 회전 애니메이션을 원하십니까? 내 코드는 180 ° 플립 애니메이션을 만듭니다. 이미지가 시각적으로 너비 = 0이되도록 90 ° (반전 플립)로 만들어 이미지를 변경하고 원래의 너비로 되돌립니다. –

+0

그게 내가 성취하려고하는 것입니다. 하프 플립 후 즉시 이미지를 변경하고 싶습니다. –

0

이 옵션을 연결하기 위해 문서를 조회 할 수 있습니다. 뒤집기가 시작되면

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn 
       animations:^(void) { 
        //do your half rotation here 
        imageView.transform = CGAffineTransformMakeScale(0, 1); 
       } 
       completion:^(BOOL finished) { 
        if(finished){ 
         imageView.image = [UIImage imageNamed:@"fb2.jpg"]; 
         [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut 
              animations:^(void) { 
               //do your second half rotation here 
               imageView.transform = CGAffineTransformMakeScale(-1, 1); 
              } completion:^(BOOL finished) { 

              }]; 
        } 
       }];