首页 > 代码库 > 渐变式切换图片
渐变式切换图片
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
渐变式切换图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。