渐变式切换图片

Posted pengyuan_D

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了渐变式切换图片相关的知识,希望对你有一定的参考价值。

ViewController.h

@interface ViewController : UIViewController<UIScrollViewDelegate>


    UIImageView *imageView1;
    UIImageView *imageView2;

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad

    [super viewDidLoad];

    UIScrollView *scrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
    scrollerView.pagingEnabled = YES;
    scrollerView.delegate = self;
    scrollerView.backgroundColor = [UIColor clearColor];
    scrollerView.contentSize = CGSizeMake(320*2, 460);
    
    [self.view addSubview:scrollerView];
    
    imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"0"]];
    imageView1.frame = CGRectMake(0, 20, 320, 460);
    imageView1.alpha = 1;
    [self.view addSubview:imageView1];
    
    imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1"]];
    imageView2.frame = CGRectMake(0, 20, 320, 460);
    imageView2.alpha = 0;
    [self.view addSubview:imageView2];
    


- (void)scrollViewDidScroll:(UIScrollView *)scrollView 

    imageView1.alpha = 1 - scrollView.contentOffset.x/320;
    imageView2.alpha = scrollView.contentOffset.x/320;
    


- (void)didReceiveMemoryWarning

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.


@end


以上是关于渐变式切换图片的主要内容,如果未能解决你的问题,请参考以下文章

js怎么做图片切换的渐变效果?

滑动 改变渐变切换图片

Android沉浸式状态栏 + scrollView顶部伸缩 + actionBar渐变

动画效果-渐变动画

用HTML怎么在网页中实现图片渐变 应该怎么写?

jQuey实现轮播图效果