如何向 UIImageView 的子类添加自定义动画属性?

发布于 2024-11-05 15:08:35 字数 765 浏览 0 评论 0原文

我有从 UIImageView 子类化的类。然后,该类的实例将作为子视图添加到我的应用程序的根类中。现在,我可以为其属性设置动画,例如 setFrame:

[UIView beginAnimations:nil context:nil];
...
[myImageView setFrame:someFrameCreatedInCode];
...
[UIView commitAnimations];

这将当前帧作为初始状态并插入 imageview 动画(它只是从左向右移动)。 这部分工作正常。

接下来我想做的是向我的类添加一个属性,例如整数类型。我希望这个属性能够指定图像编号(它的名称已格式化)并稍后制作基于帧的动画。这似乎是创建动画的好方法,因为我可以指定“曲线”来影响动画计时:

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

如何实现我自己的可以设置动画的属性?

提前致谢!

更新:如果有人需要这个,我在互联网上找到了这些教程: 博客文章示例

I have the class that I subclassed from UIImageView. The instance of this class is then added as a subview to the my application's root class. Now, I can animate it's properties, for example, setFrame:

[UIView beginAnimations:nil context:nil];
...
[myImageView setFrame:someFrameCreatedInCode];
...
[UIView commitAnimations];

This takes the current frame as the initial state and interpolates imageview animation (it simply moves from the left to the right). This part works fine.

What I would like to do next is I want to add a property to my class, say, of integer type. And I want this property to cpecify the image number (it's name is formatted) and make frame based animation later. It seems to be a nice way to create animation because I can specify the "curve" to affect the animation timing:

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

How to implement my own property which is possible to animate?

Thanks in advance!

Update: In case someone will need this I found these tutorials in the Internet: blog post, sample.

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

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

发布评论

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

评论(1

叫思念不要吵 2024-11-12 15:08:35

您可能希望将 UIView 动画与 UIImageView 动画图像一起使用。

如果您使用这样的代码:

colors = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"red_select1.png"],
                        [UIImage imageNamed:@"red_select2.png"],
                        [UIImage imageNamed:@"red_select3.png"],
                        [UIImage imageNamed:@"red_select4.png"],
                        [UIImage imageNamed:@"red_select5.png"],
                        [UIImage imageNamed:@"red_select6.png"],
                        [UIImage imageNamed:@"red_select7.png"],    
                        [UIImage imageNamed:@"red_select8.png"],nil];

animationView = [[UIImageView alloc] initWithFrame:rect];

animationView.animationImages = colors;
animationView.animationDuration = 1.0;
animationView.animationRepeatCount = 0; // loop

[animationView startAnimating];

我认为唯一的问题是同步两个动画......

You'd probably want to use the UIView animations together with the UIImageView animation images.

If you use a code like this:

colors = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"red_select1.png"],
                        [UIImage imageNamed:@"red_select2.png"],
                        [UIImage imageNamed:@"red_select3.png"],
                        [UIImage imageNamed:@"red_select4.png"],
                        [UIImage imageNamed:@"red_select5.png"],
                        [UIImage imageNamed:@"red_select6.png"],
                        [UIImage imageNamed:@"red_select7.png"],    
                        [UIImage imageNamed:@"red_select8.png"],nil];

animationView = [[UIImageView alloc] initWithFrame:rect];

animationView.animationImages = colors;
animationView.animationDuration = 1.0;
animationView.animationRepeatCount = 0; // loop

[animationView startAnimating];

I think the only problem would be synchronizing the two animations ...

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