简体   繁体   English

生成同一UIImageView的多个实例

[英]Spawning multiple instances of the same UIImageView

I have a UIImageView that I created in the nib builder and was wondering how I would create multiple instances of this same ImageView ? 我有一个在笔尖生成器中创建的UIImageView,并且想知道如何创建同一ImageView的多个实例? Right now that imageview has code attached to it, so it can move around the screen randomly but I want more than one to spawn in the middle of the screen every few seconds. 现在,该imageview附加了代码,因此它可以在屏幕上随机移动,但是我希望每隔几秒钟在屏幕中间产生一个以上的图像。

Start off by sub-classing UIImageView - override the methods you want. 首先对UIImageView进行子类化-覆盖所需的方法。

You'll probably have to set up the object in code rather than using Interface Builder. 您可能必须在代码中设置对象,而不是使用Interface Builder。 This is easier than it sounds as most of the properties can be called with the dot (.) syntax. 这比听起来容易,因为大多数属性都可以使用点(。)语法进行调用。

As for spawning every few seconds; 至于每隔几秒钟产生一次; have a look at NSTimer . 看看NSTimer

Answer to comment: 回答评论:

Try adding your newly created objects to an NSMutableArray then you can iterate through them and call the methods required. 尝试将新创建的对象添加到NSMutableArray然后可以遍历它们并调用所需的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM