动态添加 UIButtons 到屏幕 [英] Dynamically add UIButtons to screen

查看:25
本文介绍了动态添加 UIButtons 到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发基于位置的增强现实应用.当它一次显示一个对象(UIButton)时它工作得很好,但是当有更多对象时,它只显示其中一个.我一直在研究如何以编程方式向屏幕添加多个对象,但没有成功.表示的每个对象都取自一组可变字典,我尝试为这些字典中的每一个添加一个按钮,但后来我找不到任何使用 CGAffineTransform 为它们设置动画的方法.如果有人对如何实现这一点有任何想法,我将不胜感激.

I am developing an Augmented Reality app based on location. It is working perfectly when it shows one object at a time (UIButton) but when there are more, it just shows one of them. I have been researching on how to add several objects to the screen programatically with no success. Each object being represented is taken from an array of mutable dictionaries and I tried adding a button to each one of these dictionaries but then i couldn't find any way to animate them using CGAffineTransform. If anyone has any idea on how to achieve this, I would really appreciate it.

谢谢!

推荐答案

你应该能够做这样的事情

You should be able to do something like this

for( NSMutableDictionary dict in dictionaries) 
{
   float x,y; // Vary these depending on where you want the buttons to be
   UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(x,y,height,width)] autorelease];
   [augmentedRealityView addSubview:button];
}

要为它们设置动画,您可以保留一个单独的 UIButton 数组,或者将它们放入字典中并将它们拉出.您可能遇到了按钮在被放到屏幕上或从字典中被拉出之前被释放的问题.

For animating them, you can keep a separate array of the UIButtons or put them in the dictionaries and pull them out. You may have had an issue with the buttons being released before they were put on the screen or pulled out of the dictionaries.

这篇关于动态添加 UIButtons 到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆