iPhone 上实现页面循环滚动
2010-03-10 16:10:00 来源:WEB开发网if(x < minStart)
{
nx = x + perWidth ;
}
if(x >maxStart)
{
nx = x - perWidth;
}
CGRect rcVisable;
rcVisable.origin.x = nx;
rcVisable.origin.y = 0;
rcVisable.size = self.frame.size;
self.contentOffset = rcVisable.origin;
//第二步 整理里面元素的位置 scrollView下面的视图偏移 (有两个 scrollView 自带的视图,排除 )
//整理
NSArray* ary = [self subviews];
int arySize = [ary count];
NSMutableArray* aryOrderd = nil;//从 ary 里面的视图取出,按照当前 scrollview上从左到右再排序
if(arySize > 0 )
{
aryOrderd = [[NSMutableArray alloc] initWithCapacity:0];
}
if(aryOrderd != nil)
{
int i = 0;
//初开始化数组
for(i=0;i
{
UIView* pView = [ary objectAtIndex:i];
// 0x12345691 这个是我在增加 pView 到 scrollview 前给 pView 做的标记。用来区分 scrollview 内部的 view
if(pView.hidden == NO && 0x12345691 == pView.tag)
{
[aryOrderd addObject:pView];
// NSLog(@"初开始化数组 把pView=%d加入 %d ",pView, i);
// NSLog(@"pView.center.x=%f ",pView.center.x);
}
}
int aryOrdredSize = [aryOrderd count];
NSArray* aryTemp = [[NSArray alloc] initWithArray:aryOrderd];
//排序
for(i=0;i
{
UIView* pView = [aryTemp objectAtIndex:i];
CGRect rccc = pView.frame;
float centerX = CGRectGetMidX(rccc);
int pageIndex = ceil(centerX/perWidth);
if(pView.hidden == NO && 0x12345691 == pView.tag)
{
if( pageIndex <= 0 || pageIndex > aryOrdredSize )
更多精彩
赞助商链接