【发布时间】:2011-03-25 07:38:05
【问题描述】:
我想用很多不同的 UI 元素填充一个滚动视图。 因此,我想我会写一个方法来记住 scrollView 中的当前位置,并将元素添加到当前位置的 scrollView 中。
类似:
- (void)addUIElement:(id)element withWidth:(CGFloat)width andHeight:(CGFloat)height andYGap:(CGFloat)YGap {
element.frame = CGRectMake(currentScrollPos.x, (currentScrollPos.y + YGap), width, height);
[scrolly addSubview:element];
//And then set the current scroll position here
}
不幸的是,当我尝试访问 element.frame = ... 时,我收到了对不是结构或联合的成员的请求。当我尝试做 [element frame] = ... Lvalue required 作为赋值的左操作数时。
现在,首先我不确定将对象动态添加到滚动视图的最佳方法是什么。也许任何人都有更好或更简单的方法。
另一方面,我不明白为什么上面的方法不起作用?!我是否必须将我的元素转换为实际的类?我以为我不必这样做......那么我的方法就不再那么有意义了。或者至少需要更多的步骤......
【问题讨论】:
标签: iphone dynamic uiscrollview elements