如何使用 UISlider 循环显示 UIImageView 图像序列以创建动画效果
对于我目前正在开发的应用程序,我正在尝试拍摄一系列图像并将它们链接到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您无法获得
UISlider
对象来使用UIImageView
的animationImages
属性。但是,您可以维护UIImage
数组,然后设置UIImageView
对象的image
属性。为此,您必须为UIControlEventValueChanged
事件设置一个操作。将滑块的最大值设置为图像数量,即[imageArray count]
,然后根据滑块的当前值更新图像。I don't think you can get a
UISlider
object to work withanimationImages
property of anUIImageView
. However you can maintain an array ofUIImage
s and then set theUIImageView
object'simage
property. For this you will have to set an action for theUIControlEventValueChanged
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.