Iphone UIScrollView背景图像的滚动速度比内容的滚动速度快

Iphone UIScrollView背景图像的滚动速度比内容的滚动速度快,iphone,objective-c,uiscrollview,Iphone,Objective C,Uiscrollview,我刚刚注意到,在UIScrollView中有一个背景图像以及一些其他UI元素,它们以不同的速度滚动 我在主视图中创建了UIScrollView子视图,添加了以下测试代码: -(void)viewDidLoad { [super viewDidLoad]; oRulerYear.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"bg.png"]]; //bigsize! [oRulerYear setC

我刚刚注意到,在UIScrollView中有一个背景图像以及一些其他UI元素,它们以不同的速度滚动

我在主视图中创建了UIScrollView子视图,添加了以下测试代码:

-(void)viewDidLoad {
[super viewDidLoad];

oRulerYear.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"bg.png"]];
//bigsize!
[oRulerYear setContentSize:CGSizeMake(2400,100)]; 

CGFloat x = 0;
CGFloat y = 0;

CGRect rect = CGRectMake(x , y, 120.0f, 45.0f);

//label 1
UILabel *label = [[[UILabel alloc] initWithFrame:rect] autorelease];
[label setText:@"Foo"];
[oRulerYear addSubview:label];


//label 2
x = 2000;
y = 10;
rect = CGRectMake(x , y, 120.0f, 45.0f);
UILabel *label2 = [[[UILabel alloc] initWithFrame:rect] autorelease];
[label2 setText:@"Bar"];
[oRulerYear addSubview:label2];

}
滚动确实有效,但我看到两个标签上的滚动速度不同。 所以它很像1980年的pc游戏,或者是恢复了视差滚动,或者不管它叫什么。背景似乎比前景滚动得快


您知道如何防止这种行为吗?

您需要在分页UIScrollView的子视图上设置背景模式,而不是在分页UIScrollView本身上设置背景模式

#define OUTERPADDING 160
CGRect backgroundFrame = CGRectMake(-OUTERPADDING, 0,
     pagingScrollView.contentSize.width + 2*OUTERPADDING,
     pagingScrollView.contentSize.height);
UIView * backgroundView = [[UIView alloc] initWithFrame:backgroundFrame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:
        [UIImage imageNamed:@"walnut"]];
[pagingScrollView addSubview:backgroundView];

此视图必须与内容大小一样大,甚至更大,才能获得清晰的结果。OUTERPADDING用于确保模式应用于第一页之前和最后一页之后的一半屏幕上

您需要在分页UIScrollView的子视图上设置背景模式,而不是在分页UIScrollView本身上

#define OUTERPADDING 160
CGRect backgroundFrame = CGRectMake(-OUTERPADDING, 0,
     pagingScrollView.contentSize.width + 2*OUTERPADDING,
     pagingScrollView.contentSize.height);
UIView * backgroundView = [[UIView alloc] initWithFrame:backgroundFrame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:
        [UIImage imageNamed:@"walnut"]];
[pagingScrollView addSubview:backgroundView];

此视图必须与内容大小一样大,甚至更大,才能获得清晰的结果。OUTERPADDING用于确保模式在第一页之前和最后一页之后应用到一半屏幕上

+1-我得到了相同的行为,我也希望看到它消失。我也有同样的问题。背景图案(由UIColor和colorWithPatternImage制成)以接近两倍的速度水平滚动,而以零速度垂直滚动。+1-我得到了同样的行为,我也希望看到它消失。我也有同样的问题。背景图案(由UIColor和colorWithPatternImage制成)以接近两倍的速度水平滚动,而垂直滚动速度为零。