在水龍頭上,我想讓一些UIImageView對象出現在底層UIView上。 所以我創建了以下動作:新創建的UIImageView在添加爲子視圖時不會顯示
- (IBAction)startStars: (id) sender
{
UIView* that = (UIView*) sender; // an UIButton, invisible, but reacting to Touch Down events
int tag = that.tag;
UIView* page = [self getViewByTag:mPages index:tag]; // getting a page currently being viewed
if (page != nil)
{
int i;
UIImage* image = [UIImage imageNamed:@"some.png"];
for (i = 0 ; i < 10 ; ++i)
{
// create a new UIImageView at the position of the tapped UIView
UIImageView* zap = [[UIImageView alloc] initWithFrame:that.frame];
// assigning the UIImage
zap.image = image;
// make a modification to the position so we can see all instances
CGPoint start = that.layer.frame.origin;
start.x += i*20;
zap.layer.position = start;
[page addSubview:zap]; // add to the UIView
[zap setNeedsDisplay]; // please please redraw
[zap release]; // release, since page will retain zap
}
[image release];
}
}
不幸的是,什麼也沒有顯示出來。代碼被調用,創建的對象,圖像被加載,甚至屬性如預期。 頁面本身是一個真正的基本UIView,使用界面構建器創建以包含其他視圖和控件。
不過,什麼都不由此可以看出....
有沒有人一個想法是什麼,我做錯了什麼?我是否需要設置alpha屬性(或其他)?
感謝
Zuppa
我的第一個想法是你的'getViewByTag:index:'函數出了問題。你可以發佈這個呢? –
確實。情況就是如此。我從來沒有想到這一點.. – Zuppa