2014-10-06 5 views
1

화면 상단에 imageView가 있습니다. 특정 시간 간격으로 이미지를 전환하고 애니메이션으로 만들려면 (실제로 애니메이션이 무엇인지 지정하지 않아야합니다.) 예를 들어, 사라질 수 있습니다.) 해당 코드 스 니펫을 추가 할 것을 제안했습니다.이미지 전환시 애니메이션을 적용하는 방법

// load all the frames of our animation 
    self.imageSlideshow.animationImages = [NSArray arrayWithObjects: 
             self.firstImageIps, self.secondImageIps, self.thirdImageIps, self.fourthImageIps, self.fifthImageIps, nil]; 

    // all frames will execute in 1.75 seconds 
    self.imageSlideshow.animationDuration = 1.75; 
    // repeat the animation forever 
    self.imageSlideshow.animationRepeatCount = 0; 
    // start animating 
    NSLog(@"that one called?"); 
    [self.imageSlideshow startAnimating]; 

여기에는 이미지가 전환없이 애니메이션없이 표시됩니다. 여기 더 심각한 문제가 있습니다. 지속 시간을 3 초로 설정하면 이상한 행동이 시작됩니다 (모든 이미지가 아닌 첫 번째 이미지가 두 번째 및 세 번째로 자주 표시됨). 전체 이미지를 얻을 수없는 것처럼 보입니다. 반복하고 약간의 시간이 지나면 첫 번째 이미지로 이동).

타이머 간격 (예 : 5-7 초)으로 애니메이션을 전환하는 방법은 무엇입니까?

감사의 말을 들어주세요.

답변

1
-(void)animateImages 
{ 
    count++; 

    [UIView transitionWithView:imageSlideshow 
         duration:2.0f 
         options:UIViewAnimationOptionTransitionCrossDissolve 
        animations:^{ 
         imageSlideshow.image = [imagesArray objectAtIndex: count % [imagesArray count]]; 
        } completion:^(BOOL finished) { 
         [self animateImages]; 
        }]; 
} 

이 코드 스 니펫은 모든 유형의 애니메이션을 추가하는 데 도움이됩니다.

+0

정확히 내가 원하는 것을 Ramesh에게 감사드립니다. –

1

애니메이션을 수행하는 가장 간단한 방법 중 하나입니다.

코드 예제 :

[UIView animateWithDuration:0.3 animations:^{ 
         //change alpha with animation. 
         self.friendsTableView.alpha = 1.f; 
        } completion:^(BOOL finished) { 

        }]; 

이 애니메이션뿐만 아니라 delayoptions로 설정 될 수있다. 내가 아는 한, 적은 비용으로 적절한 애니메이션을 설정하는 가장 간단한 방법입니다.

+0

매우 올렉 감사를, 많은 도움이됩니다! –

+0

당신은 오신 것을 환영합니다! –

2

이 하나를 시도해보십시오

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.imgArr = [[NSArray alloc] initWithObjects:@"DSC06715.JPG",@"Snapshot_20121113_18.JPG",@"IMAG1689.jpg",@"IMAG1720.jpg",@"IMAG1396.jpg", nil]; 

    [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(performTransition) userInfo:nil repeats:YES]; 

    } 

    -(void)performTransition 
    { 
     int randImg = arc4random()%self.imgArr.count; 
     [self.imageView1 setImage:[UIImage imageNamed:[self.imgArr objectAtIndex:randImg]]]; 

     CATransition *transition = [CATransition animation]; 
     transition.duration = 1; 
     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 

     NSString *types[4] = {kCATransitionFade}; 
     transition.type = types[1]; 
     transition.delegate = self; 
     [self.imageView1.layer addAnimation:transition forKey:nil]; 
    } 
1

이보기 사이의 애니메이션은 공간적 UIView 방법을 사용할 수 있습니다하려면 :

- (void)makeCrossDissolveAnimation { 
    NSArray *images = self.imageSlideshow.animationImages; 
    static int counter = 0; 
    UIImageView *startView = [[UIImageView alloc] initWithImage:images[counter]]; 
    counter = (counter+1) % [images count]; 
    UIImageView *endView = [[UIImageView alloc] initWithImage:images[counter]]; 
    [UIView transitionFromView:startView toView:endView duration:ELAnimationDuration 
         options:UIViewAnimationOptionTransitionCrossDissolve 
        completion:^(BOOL finished) { 
         // Your completion block 
        }]; 
} 
+0

EXC_Arithmetic (code = ExC_i386_DIV, subcode = 0x0) 오류가 발생합니다. –

관련 문제