2016-04-11 39 views
0

'Image' Animasyonları 'UIView' de Different Locations'a nasıl verilir?Bir UIView'deki Farklı Konumlarda birden çok resme resim animasyonları nasıl verilir?

1) 3 resimde vardı.

2) i animatedly 3 different locations de bu 3 Images ekle istiyorum, bir görüntü some duration ile animatedly teker eklemek demektir ??

Bunu nasıl başarabilirim?

+0

Eğer Perticular alanı için yavaş hızlı uiimageview animasyon ihtiyacınız var? – Shreyank

+2

UIView animateWithDuration? –

+0

@Shreyank .... Hızlı değil Hızlı ... ama 3 farklı yerde bir süre sonra 3 resim eklemek istiyoruz ... tek bir yerde bir resim, o resmi yerleştirdikten sonra, bir sonraki görüntü canlandırıp gel –

cevap

0

şartının olarak, ikinci görüntünün canlandırılması için ilk görüntü animasyon bu amaç kullanımı tamamlama bloğu için bir

görüntüyü tek Canlandırmak istediğiniz ve benzeri kodunun altına

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",1]]]; 
[imgView setBackgroundColor:[UIColor redColor]]; 

UIImageView *imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",2]]]; 
[imgView2 setBackgroundColor:[UIColor redColor]]; 

UIImageView *imgView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"-t%d",2]]]; 
[imgView3 setBackgroundColor:[UIColor redColor]]; 

[self.view addSubview:imgView]; 
[self.view addSubview:imgView2]; 
[self.view addSubview:imgView3]; 

[UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 

    [imgView setFrame:CGRectMake(0, 0, 150, 150)]; 


} completion:^(BOOL finished) { 

    [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 
     [imgView2 setFrame:CGRectMake(self.view.frame.size.width - 150, 0, 150, 150)]; 

    } completion:^(BOOL finished) { 

     [UIView animateWithDuration:0.5 delay:1.0 options:UIViewAnimationOptionLayoutSubviews animations:^{ 
      [imgView3 setFrame:CGRectMake(0, self.view.frame.size.height - 150, 150, 150)]; 

     } completion:^(BOOL finished) { 


     }]; 

    }]; 

}]; 

gibi Yardım edecek

+0

@PKT .... kodunuz benim için iyi çalışıyor –

0

3 defa _redView, _greenView ve dışında başka bir konuma bir gelenler taşımak için bir yöntem, aşağıdaki _blueView çek olan düşünelim. İsterseniz spesifik verebileceğiniz rastgele konum kullanmıştım. Here you can have working example of it sadece çalışma alanının ViewAnimationsTest projesini seçin ve çalıştırın.

- (int) randomFloatingGenerator : (int) max{ 
    return arc4random() % max; 
} 

- (void) animate3Views { 
    [UIView animateWithDuration:2.0 
        animations:^{ 
         _redView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]); 
         _greenView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]); 
         _blueView.transform = CGAffineTransformMakeTranslation([self randomFloatingGenerator : 270], [self randomFloatingGenerator:480]); 

        } completion:^(BOOL finished) { 
         [self animate3Views];//if don;t want continuous translation remove this line 
        }]; 
} 
+0

Burada çalışma örneği var, https://github.com/rptwsthi/DevelopmentSupportWorkspace sadece ViewAnimationsTest projesi seçin çalışma alanı ve koş. – rptwsthi

+0

@rptwsthi ... bu örneklerde, hangisini kullanmam gerektiğini söyler misin –

0

Muhtemelen bunu yapmanın en kolay yolu, gecikmeli olarak adlandırılan 3 animasyonu kullanmaktır. myViews hareketli olmak görüş dizi

for (NSInteger i = 0; i < 3; i++) { 
     UIView *view = myViews[i]; 
     CGRect frame = [self frameForViewAtIndex: i]; 
     NSTimeInterval duration = 0.5; 
     NSTimeInterval delay = i * 0.5; 

     [UIView animateWithDuration: duration delay: delay options: 0 animations: ^{ 
      view.frame = frame; 
     } completion: nil]; 
    } 

, frameForViewAtIndex: görünümü karşılık gelen çerçeve döner bir yöntemdir.

+0

@roselovely Bu kod parçasında net olmayan bir şey var mı? –

+0

.... Görüntülerin nasıl ekleneceğini anlatabilir misiniz? –