2014-09-03 160 views
0

我做了簡單的動畫,但要動畫添加到圖像像從左至右像滑塊一樣,我有圖片,如何編程製作動畫的陣列,動畫圖像向左像幻燈片

-(void) slideImages 
{ 
    NSMutableArray *imagesArrays= [[NSMutableArray alloc]init]; 
    for (SliderDC *slider in imagesArray) { 
     sliderImageName = slider.sliderImagePath; 

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",KWURL ,sliderImageName]]]; 

     UIImage *imgOne = [UIImage imageWithData:imageData]; 

    if(imgOne) 
     [imagesArrays addObject:imgOne]; 
} 

// after adding all image in array then add animation. 
UIImageView* animatedImageView; 
if ([[UIScreen mainScreen] bounds].size.height == 568){ 
     animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 65, 320, 150)]; 
} 
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 98, 768, 228)]; 
} 
else 
{ 
animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 65, 320, 118)]; 
} 
animatedImageView.animationImages = imagesArrays; 
animatedImageView.animationDuration = 20.0f; 
animatedImageView.animationRepeatCount = 0; 
[self.view addSubview: animatedImageView]; 
[animatedImageView startAnimating]; 

} 

回答

2

試試這個..

-(void) slideImages 
    { 
    NSMutableArray *imagesArrays= [[NSMutableArray alloc]init]; 
    for (SliderDC *slider in imagesArray) { 
     sliderImageName = slider.sliderImagePath; 

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",KWURL ,sliderImageName]]]; 

     UIImage *imgOne = [UIImage imageWithData:imageData]; 

    if(imgOne) 
     [imagesArrays addObject:imgOne]; 
    } 


- (IBAction)startAnimation:(UIButton *)sender 
{ 
    slideTransition = [CATransition animation]; // CATransition * slideTransition; instance variable 
    slideTransition.duration = 0.35; 
    slideTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    slideTransition.type = kCATransitionPush; 
    slideTransition.delegate = self; 
    NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:0.50 target:self selector:@selector(slideShow) userInfo:nil repeats:YES]; 
    [timer fire]; 
} 
-(void)slideShow 
{ 
    slideTransition.subtype =kCATransitionFromLeft; // or kCATransitionFromRight 
    [animatedImageView.layer addAnimation:slideTransition forKey:nil]; 

    if (index < imagesArrays.count-1) // NSUInteger index; instance variable 
    { 
     index++; 

    } 
    else 
    { 
     index=0; 
    } 
    animatedImageView.image =[imagesArrays objectAtIndex:index]; 

} 
+0

在創建新圖像的動畫時,這不顯示黑屏嗎? – Ahmed 2016-06-06 09:53:54

2

您可以簡單地使用DRDynamicSlideShow

創建漂亮的動畫分頁UIScrollViews。隨着UIScrollView被分頁,輕鬆地創建視圖。這非常適合iOS應用中的歡迎屏幕和簡介視圖。

特點

1線的每動畫代碼。

任何類型的值都可以是動畫的。

塊驅動。

1
-(void) slideImages 
{ 
NSMutableArray *imagesArrays= [[NSMutableArray alloc]init]; 
for (SliderDC *slider in imagesArray) { 
    sliderImageName = slider.sliderImagePath; 

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",KWURL ,sliderImageName]]]; 

    UIImage *imgOne = [UIImage imageWithData:imageData]; 

if(imgOne) 
    [imagesArrays addObject:imgOne]; 
} 



UIImageView* animatedImageView; 
if ([[UIScreen mainScreen] bounds].size.height == 568){ 
    animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 65, 320, 150)]; 
} 
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 98, 768, 228)]; 
} 
else 
{ 
animatedImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 65, 320, 118)]; 
} 

[self.view addSubview: animatedImageView]; 

self.animatedImageView.animationImages = imagesArrays; 

self.animatedImageView.animationDuration=1.0; 
self.animatedImageView.animationRepeatCount=1; 
self.animatedImageView.image = [self.imageViewAnimation.animationImages lastObject]; //to stop animation at last image. 
[self.animatedImageView startAnimating]; 
+0

它會像動畫滑塊? – NullData 2014-09-03 07:10:18

+0

但我有來自webservies的圖像 – NullData 2014-09-03 07:10:39