向上滑动时,创建效果顶部图像会被内容覆盖 [英] Create effect top image is overlaid by content when sliding up

查看:31
本文介绍了向上滑动时,创建效果顶部图像会被内容覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在图像中创建一个效果,但是我不知道该怎么做(也不知道如何调用该效果进行搜索).您可以在图片中看到,首先我们在页面顶部有一个图片.之后,当我们向上滚动时,图像将向上移动,而内容将以更高的速度移动以覆盖图像.你能给我一个链接或建议吗?

I have to create an effect like in the images but I don't know how to do it (and also don't know how to call this effect to search). You can see in the pictures, at first we have an image at the top of page. After that, when we scroll up, the image moves up while the content moves with higher speed to cover the image. Can you give me a link or a suggestion?

推荐答案

首先使用 IBOutlet 在您的应用中获取图像视图和滚动视图.

First of all take imageview and scrollview in your apps with IBOutlet.

在您的 YourViewController.h 文件中

@property(nonatomic,retain) IBOutlet UIImageView *imagev;

@property(nonatomic,retain) IBOutlet UIScrollView *scr;

在您的 YourViewController.m 文件中

- (void)viewDidLoad
{
    scr.contentSize = CGSizeMake(320,850);
    scr.decelerationRate = UIScrollViewDecelerationRateNormal;
    [super viewDidLoad];
}

根据scrollview委托中的滚动设置imagev帧.

Set imagev frame according to scrolling in scrollview delegate.

-(void)scrollViewDidScroll:(UIScrollView *)callerScrollView
{
    
    NSLog(@"%f",callerScrollView.contentOffset.y);
    
    [imagev setFrame:CGRectMake(imagev.frame.origin.x, - 0.5 *callerScrollView.contentOffset.y, imagev.frame.size.width, imagev.frame.size.height)];

}

输出:

这篇关于向上滑动时,创建效果顶部图像会被内容覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆