如何使用 UISlider 循环显示 UIImageView 图像序列以创建动画效果

发布于 2024-11-15 20:45:21 字数 1368 浏览 4 评论 0原文

对于我目前正在开发的应用程序,我正在尝试拍摄一系列图像并将它们链接到 UISlider。与滑块交互将创建动画效果,在帧之间循环。我已经能够从一系列图像创建一个独立的动画,但是我不太确定如何添加 UISlider 并创建适当的链接以实现所需的效果。

这是我到目前为止所拥有的...

- (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];

有什么线索吗?

For the app i am currently working on i am trying to take a series of images and link them to a UISlider. Interacting with the slider will create an animated effect, cycling through the frames. I have been able to create a standalone animation from the series of images, however i am not too certain about how to add the UISlider and make the appropriate links to achieve the desired effect.

Here is what i have so far...

- (void) viewDidLoad{

//---Animate Images Array----
/*

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];

Any clues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给不了的爱 2024-11-22 20:45:21

我认为您无法获得 UISlider 对象来使用 UIImageViewanimationImages 属性。但是,您可以维护 UIImage 数组,然后设置 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];
}

I don't think you can get a UISlider object to work with animationImages property of an UIImageView. However you can maintain an array of UIImages and then set the UIImageView object's image property. For this you will have to set an action for the UIControlEventValueChanged event. Set the max value of the slider to the number of images i.e. [imageArray count] and then based on the current value of the slider, update the image.

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

    [slider setValue:roundf(slider.value) animated:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文