Iphone 在UIView上滚动带图案的背景

Iphone 在UIView上滚动带图案的背景,iphone,ios,ipad,Iphone,Ios,Ipad,我有一个简单的UIView,我用图案背景填充它,像这样 self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundPattern"]]; self.bounds = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height); [UIView animateWithDuration:1. delay:0

我有一个简单的UIView,我用图案背景填充它,像这样

    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundPattern"]];
self.bounds = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
[UIView animateWithDuration:1. delay:0. options:UIViewAnimationOptionRepeat animations:^{
    self.bounds = CGRectMake(0, 100, self.bounds.size.width, self.bounds.size.height);
} completion:nil];
我希望能够通过修改视图的bounds属性来操纵视图的原点,并使背景随着原点的变化而移动(就好像背景固定在内容上,而不是浮动在内容后面一样)。这可能吗?当前,背景似乎固定在视图的框架上,而不是其边界上,并且当内容滚动时,模式不会滚动

要更改原点,我将使用如下的块动画

    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundPattern"]];
self.bounds = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
[UIView animateWithDuration:1. delay:0. options:UIViewAnimationOptionRepeat animations:^{
    self.bounds = CGRectMake(0, 100, self.bounds.size.width, self.bounds.size.height);
} completion:nil];

使用该代码,我的孩子视图会反复滚动和重置,但背景会保持不变。是否可以指定一个与视图一起滚动的背景?

我找不到任何关于将背景图案“粘贴”到视图的原始系统的信息。我的应用程序解决方案是创建一个子视图,并在其上设置背景模式。然后,子视图将随着原点的更改而移动,背景图案也将随之移动。该解决方案的问题是,子视图必须足够大,以覆盖可能的原点范围,如果内容区域可能任意大,则很难处理该范围。

我无法找到任何关于将背景图案“粘贴”到视图原点系统的方法。我的应用程序解决方案是创建一个子视图,并在其上设置背景模式。然后,子视图将随着原点的更改而移动,背景图案也将随之移动。该解决方案的问题在于,子视图必须足够大,以覆盖潜在原点的范围,如果内容区域可能任意大,这可能很难处理。

您可以按照用户平移的方向再次生成视图实例,并将其添加到NSMutableArray中,以便根据世界的偏移量进行访问和移动。

您可以按照用户平移的方向再次生成视图实例并将其添加到NSMutableArray中,以便根据世界的偏移量进行访问和移动