【发布时间】:2011-07-16 19:19:36
【问题描述】:
我将 UIViews 添加到 UIScrollView 一个下一个。当用户滚动并且当前 UIView 传递一个矩形时,它必须更改 UIView 的背景颜色。 如何跟踪子视图在定义的矩形内?
- (void) showViews {
CGRect scrollRect = CGRectMake(0.0f, 44.0f, 704.0f, 704.0f);
UIScrollView *aScroll = [[UIScrollView alloc] initWithFrame:scrollRect];
float yPos = 20.0f;
//the rectangle to trace intersection
CGRect intersectRect = CGRectMake(0.0f, 200.0f, 704.0f, 400.0f);
for (UIView* view in arrayOfViews) {
CGRect viewRect = CGRectMake(100.0f, yPos, 320.0f, 480.0f);
view.frame = viewRect;
[aScroll addSubView:view];
yPos = yPos + 340.0f;
aScroll.contentSize = CGSizeMake(704.0, yPos);
}
}
【问题讨论】:
-
抱歉,请问您有什么问题?
-
@PengOne 抱歉,问题在标题中。如何在定义的矩形内跟踪子视图?
-
滚动停止时或滚动时是否需要更改颜色?
-
@Vince 我需要在滚动时更改它。当内部 intersectRect 颜色为蓝色时,外部颜色为绿色。只是为了简化。
标签: ios xcode uiscrollview