渐变式切换图片
2014-11-01 17:24
239 查看
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
@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
相关文章推荐
- Javascript 点击切换图片(小demo)
- js实现图片从左往右渐变切换效果的方法
- javascript 仿flash新闻图片切换效果-推荐
- IOS开发之UIButton同时设置图片文字以及触发按钮时文字图片的切换
- js实现图片从左往右渐变切换效果的方法
- jquery 实现背景图片循环切换,显示隐藏div
- <jQuery>首页图片切换/轮播
- 从零開始学android<ImageSwitcher图片切换组件.二十六.>
- jquery实现LED广告牌旋转系统图片切换效果代码分享
- 点击切换图片
- jQuery实现图片切换效果
- 图片切换
- 网站制作一 : 从简单做起,通过a属性实现导航图片切换
- jquery 手机 图片切换 例子 网址
- 【自用】C# 中图片切换的几种过渡动画特效
- 【转】Android android listview的HeadView左右切换图片(仿新浪,网易,百度等切换图片)
- js实现支持手机滑动切换的轮播图片效果实例
- 19.制作自动切换滚动的图片轮播
- 左右按钮,切换多张图片