2013-06-26 105 views
1

我试图创建一个非常简单的视差效果,当用户滚动UIScrollView。我在我的滚动视图上使用scrollViewDidScroll方法,即所有工作。我可以记录该方法的所有内容,因此我知道当UIScrollView滚动时它会被触发。问题是我试图对UIScrollView的内容做出任何更改失败。可能是渲染问题?在滚动期间,UIScrollView是否不重新呈现其内容?更改UIScrollView滚动UIImageView中心点

我试着改变UIImageView(imageView)的框架和中心点,没有任何工作。任何想法可能会发生什么,我没有得到任何形式的错误或任何东西。

-(void)scrollViewDidScroll:(UIScrollView *)body { 

    float y = body.contentOffset.y; 

     imageView.center = CGPointMake(imageView.bounds.size.width/2, (imageView.bounds.size.height/2) - y/2); 

    // Tried this as well 
    //[imageView setFrame:CGRectMake(0, 0, imageView.bounds.size.width, imageView.bounds.size.height + (y * 2))]; 

    NSLog(@"We are scrolling..."); 

} 

回答

2

想通了,我实际上需要在ScrollView中使用ImageView的实例。任何其他人试图弄清楚这一点,我做了一个小黑客,但它的作品。

/* Paralax Scrolling */ 
-(void)scrollViewDidScroll:(UIScrollView *)body { 

    float y = body.contentOffset.y; 

    // When adding (body) image view to scroll view I assigned a tag of 100 to it. 
    [body viewWithTag:100].center = CGPointMake([body viewWithTag:100].bounds.size.width/2, ([body viewWithTag:100].bounds.size.height/2) + y/2); 

} 
+0

真棒男人...很酷!!! – Nits007ak