码迷,mamicode.com
首页 > 其他好文 > 详细

渐变式切换图片

时间:2014-11-02 09:30:25      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:渐变   切换图片   透明度   动画   

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


渐变式切换图片

标签:渐变   切换图片   透明度   动画   

原文地址:http://blog.csdn.net/pengyuan_d/article/details/40682419

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!