2011-06-16 43 views
0

對於我正在處理的應用程序,我正在嘗試拍攝一系列圖像並將它們鏈接到UISlider。與滑塊交互會創建一個動畫效果,循環播放幀。我已經能夠從一系列圖像創建一個獨立的動畫,但是我不太確定如何添加UISlider並製作適當的鏈接以實現所需的效果。如何使用UISlider循環訪問UIImageView圖像序列以創建動畫效果

這裏是我迄今爲止...

- (void) viewDidLoad{ 

// ---動畫圖像陣列---- /*

NSArray *images = [NSArray arrayWithObjects: 
        [UIImage imageNamed:@"frame1.png"], 
        [UIImage imageNamed:@"frame2.png"], 
        [UIImage imageNamed:@"frame3.png"], 
        [UIImage imageNamed:@"frame4.png"], 
        [UIImage imageNamed:@"frame5.png"], 
        [UIImage imageNamed:@"frame6.png"], 
        [UIImage imageNamed:@"frame7.png"], 
        [UIImage imageNamed:@"frame8.png"], 
        [UIImage imageNamed:@"frame9.png"], 
        [UIImage imageNamed:@"frame10.png"], 
        nil]; 

CGRect frame = CGRectMake(0,44,703,704); 
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame]; 
imageView.animationImages = images; 
imageView.contentMode = UIViewContentModeScaleAspectFit; 


imageView.animationDuration = 4; 
imageView.animationRepeatCount = 0; 
[imageView startAnimating]; 

[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:imageView cache:YES]; 
[self.view addSubview:imageView]; 


[imageView release]; 
[super viewDidLoad]; 

任何線索?

回答

1

我不認爲你可以得到一個UISlider對象與animationImages物業UIImageView。但是,您可以維護一組UIImage s,然後設置UIImageView對象的image屬性。爲此,您將不得不爲UIControlEventValueChanged事件設置操作。將滑塊的最大值設置爲圖像數量,即[imageArray count],然後根據滑塊的當前值更新圖像。

- (void)valueChanged:(UISlider *)slider { 
    NSInteger currentImageIndex = lroundf(slider.value); 
    imageView.image = [imageArray objectAtIndex:currentImageIndex]; 

    [slider setValue:roundf(slider.value) animated:YES]; 
} 
相關問題